Install Xcode first. You will need the one from the Mac App Store. You will need version 4.3 or above.
Then install homebrew. Go to this link (https://github.com/mxcl/homebrew/wiki/installation) to find the installation command. As of May 2012, the command is:
/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
Then after the process finishes (it took like 30 seconds), run
This is just to make sure your environment is good to move on. If your Xcode is old you will get a complain here like the following:
$ brew doctor Error: You have Xcode 4.1, which is outdated. Please install Xcode 4.3.
I have installed the mcrypt lib myself, and I got warnings about that (see below). If that happens to you just ignore it.
Error: Unbrewed dylibs were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. Unexpected dylibs: /usr/local/lib/libmcrypt.4.4.8.dylib Error: Unbrewed .la files were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. Unexpected .la files: /usr/local/lib/libmcrypt.la Error: Unbrewed static libraries were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. Unexpected static libraries: /usr/local/lib/libarmdis.a /usr/local/lib/libAstrisAPI.a
Then Install git by:
brew install git
You can make sure git is successfully installed by issuing:
Then install MySQL. Now, I believe you already have it if you are using Lion. Type the following command to see if you have mysql installed.
mysql -u root
If you get a mysql prompt, then you are good. If not, install it by issuing:
brew install mysql
You can alternatively install MAMP if you like, as MySQL will be one of the packages inside MAMP.
Then install RVM. This is the Ruby Version Manager. It will make your life so much easier down the road.
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
After installing rvm, edit your ~/.bash_profile file to include the following line. Make sure it’s there.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Then source your bash_profile file as you always do.
Now Install Ruby. Lion already has 1.8 but we are going to install the latest 1.9.3.
rvm install 1.9.3
It will start downloading and installing. Just wait until it’s done, all automated. Isn’t it nice?
After installing check your ruby version by issuing:
You should see something like ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0].
Then lastly install Rails.
gem install bundler gem install mysql2 gem install rails
Now that we have rails installed, it’s time to test it out! Let’s create a simple test app in our home directory.
cd rails new mytest
All your new projects files are inside the newly created directory called mytest. Now to run this app issue:
cd mytest rails server
You will see something like the following:
$ rails server => Booting WEBrick => Rails 3.2.3 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-05-18 17:09:11] INFO WEBrick 1.3.1 [2012-05-18 17:09:11] INFO ruby 1.9.3 (2012-04-20) [x86_64-darwin11.3.0] [2012-05-18 17:09:11] INFO WEBrick::HTTPServer#start: pid=7008 port=3000
So open a web browser and type in http://0.0.0.0:3000 into the location bar. If you see the rails welcome page, then congratulations! You are on Rails now!
You can find more very useful info on the rails official site at http://guides.rubyonrails.org/getting_started.html
I heavily borrowed much content and edited some portions from http://thinkvitamin.com/code/ruby-on-rails/installing-ruby-rails-and-mysql-on-os-x-lion/.
Update (July 10th, 2012): This article is even better! http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac/
2 thoughts on “Installing Ruby on Rails in osx”
rails s/usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’: no such file to load openssl (LoadError)from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’…..my rails vriseon is 3.0.1. and i am not using rvm. Could you tell me how can i get rid of this error.
See if this helps?