Update Ruby and Rails on Mac OS X
The system version of Ruby is a bit outdated. In order to update it you should install the Ruby Version Manager or RVM, and not touch the System’s Ruby version. Trying to install it through MacPorts also gave me a bunch of problems, especially in OS X Lion (10.7).
This install also requires Git Version Control system.
If you’re using MacPorts you can install it by running
sudo port install git
But like I said some Ruby and Rails applications do not play well with MacPorts so you will sooner or later should migrate to Homebrew. Here is one of such problems due to mismatched OpenSSL MacPort library versions, that caused me to have to reinstall the whole thing…
Well using the system’s version of ruby it is easy to install Homebrew:
ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
and then install Git
brew install git
Now you can install RVM. Just Copy & Paste the whole line and run it as a single line in your terminal
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
I usually install RVM in my home directory, and run the previous command with my regular user. This is ok since we mostly use our Macs for development, with only one developer on that machine.
If you need to install RVM system wide you can run:
sudo bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
Now you need to add RVM to your shell so it can do its magic.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bash_profile
Close your Terminal and reopen it. This will force it to process the code we just entered into .bash_profile. You can also run the following:
. ~/.bash_profile
Now you need to make sure you have the latest Xcode from Apple. You can download it from the App Store for free, or install it from your Mac OS X installation DVD.
If you are a die hard fan of MacPorts, please remove it from the PATH so Ruby does not compile against its libraries causing all sorts of errors later on. It usually suffices to remove all references to /opt/local from the /etc/profile, but your configuration maybe a little bit different.
Now that you have installed Xcode and removed the MacPorts from the PATH you can continue
At the time of this writing the current stable version of Ruby was 1.9.3 so that is what I use, you should probably use the latest sable version, and not 1.9.3, by the time you follow this procedure…
rvm install 1.9.3
If you’re on Mac OS X Lion 10.7.2 with Xcode 4.2.1 you may get a compilation error. In that case run
rvm install 1.9.3 --with-gcc=clang
Once it finishes downloading, compiling and installing ruby you can do
rvm --default use 1.9.3
To use the ruby version we just installed, and to make it the default version.
RVM is kind of neat since it does not disturb the system version of Ruby and allows you to maintain and work with different versions of Ruby so you can make sure your older projects that require older versions of Ruby, Rails or some other Gem still run even when you upgrade to newer versions.
RVM is kind of like a virtual machine, or environment that allows you to keep separate Ruby installs that will coexist peacefully, and that is why you should use it and not replace the system Ruby version.
RVM allows for the creation and use of several Gem Repositories or gemsets, that you can keep for each of your projects, and this is an invaluable feature so you don’t get stuck into gem dependency issues later on.
By default a global gemset is created and all gems installed to global will be shared among all the other gemsets that you create for a specific ruby version maintained by RVM.
You should install gems, that like Rails, will be shared by all projects running under a Ruby version. So lets install some of the basic gems to get us going.
rvm gemset list
You should get something like:
gemsets for ruby-1.9.3-p0 (found in /Users/pedro/.rvm/gems/ruby-1.9.3-p0)
global
Lets double check that we’re using the Ruby version we just installed:
bigdiver$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
bigdiver$ gem -v
1.8.10
Nice!
Install sQlite3, JSON, and Rails
gem install sqlite3 json rdoc rails cheat
If you get UTF-8 errors just set the LANG and LC_CTYPE environment variables. I usually do it in the /etc/profile, but you can do it in the .bash_profile in your home directory.
Add the following lines to one of them and “source” them into your environment
export LC_CTYPE="utf-8"
export LANG=en_US.UTF-8
. /etc/profile
or
. ~/.bash_profile
And then install your gems.
[...] a comment » You should first install the Ruby Version Manager (RVM), you can follow my other article on how to do it and get the latest version of Ruby and Rails working on your [...]
Working with Ruby Version Manager « BigDiver
November 24, 2011 at 6:10 pm