Update: There is an updated version of this article at How to Install Ruby on Rails on Mac - Updated
This is first tutorial in ruby on rails series. This post will show you the exact steps you need to follow to get Ruby on Rails up and running on your Mac.
If you are new to Terminal and Mac os X in general; you will find this helpful.
Since mac gives us shell access, we can take advantage of Linux goodies. The most useful and recommended tool is rvm. It stands for Ruby Version Manager. It's a command-line tool which allows you to easily install, manage, and work with multiple ruby environments including sets of gems. With new versions of ruby getting released periodically, it's nice to have a version manager.
OS X comes with ruby installation by default. Check the version of installed ruby -
ruby -vMost likely, you will see ruby 1.8.7 pre-installed for you. Now it's time to upgrade to either 1.9.2 or 1.9.3.
Step 1 - git installation
rvm requires git to be installed on your system. If you already have git, skip to the next step.
git is a popular version control manager used by many open source projects including linux kernel and android. Download the appropriate installer from here
Open the .dmg file and you will find the installer package. Follow the instructions to install git.
To verify, inside Terminal type git and you should see a list of available git commands.
Step 2 - RVM installation
For GUI lovers, there is GUI version available just for Mac users. Download from here - http://jewelrybox.unfiniti.com/
For rest of of us who love Terminal, follow along. It's one step process. Inside Terminal run this command -
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)It downloads rvm and installs it for you.
Step 3 - Load RVM
This step is analogous to adding rvm to your $PATH or environment variable.
Again inside Terminal,
echo ‘[[ -s "$HOME/.rvm/scripts/rvm" ]] && source “$HOME/.rvm/scripts/rvm”‘ >> ~/.bash_profileIt add rvm scripts to your bash profile so that every time you open the terminal, rvm gets loaded in the Terminal.
Step 4 - Verify RVM installation
Restart Terminal. Use cmd + Q to close the application and open it again.
Now it's time to see how rvm looks. Type rvm in Terminal and you will be greeted by a long message.
Step 5 - Download and Install xcode
xcode covers most of the dependencies for new Ruby installation. It also includes gcc compiler and other important development tools. You can download Xcode from Apple’s App Store. Search for “xcode” and click the install button.
Step 6 - Upgrade to Ruby 1.9.2
We will use 1.9.2 for this tutorial as it's the most recent stable version.
$ rvm list known # MRI Rubies 1.8.6[-p420] 1.8.6-head 1.8.7[-p352] 1.8.7-head 1.9.1-p378 1.9.1[-p431] 1.9.1-head 1.9.2-p180 1.9.2[-p290] 1.9.2-head ruby-head ...This is the list of all components known and managed by rvm.
We will install ruby 1.9.2.
$ rvm install 1.9.2Next, check the installed versions by rvm using
$ rvm listNow start using 1.9.2 by this command
$ rvm use 1.9.2
Your current ruby version is 1.9.2 but you might want to make this as your default version.
$ rvm --default 1.9.2Check the version in another Terminal window
$ ruby -v $ which rubyYou are almost done!
Step 7 - Install gems
Ruby gems are managed by a command line tool called 'gem' and it's preinstalled for you by rvm. You can use it to install other gems such as rails or sinatra etc.
$ gem install railsrvm chooses gems depending on the current version of ruby and you can switch between different version by using 'rvm use' command.
Step 8 - Create Your rails project (optional)
cd ~ mkdir rails-apps cd rails-apps rails new hello cd hello rails sIn your browser, open localhost:3000/. You have successfully installed Ruby on Rails on mac :)