I’ve been away from Ruby and Rails for a long time so before I started working in the environment again, I thought it best to ensure my iMac was up to date with the appropriate software.
If you’re at all serious about using Ruby as a development tool, I sincerely recommend using ‘rvm’ to manage your Ruby versions (as you’ll already know if you’ve read any of my other posts!). Ruby is in continuous development and unlike some languages, it is often the case that the syntax in a new version of Ruby might break code that runs perfectly in an earlier version of the language.
A Ruby Version manager is therefore essential to anybody who works in the Ruby development space for any length of time. rvm is perfect for the job and there are extensive instructions there to cope with installations on OSX, Ubuntu and Windows. I haven’t checked but I’m sure that anybody running a Unix flavor other than Ubuntu would also be able to find help if required.
The first thing I did was update rvm. A quick look on the rvm site told me that the update command was still
rvm get stable
which ran perfectly.
I then checked which Rubies I had installed, noting that Rails 4 (my intended destination) preferred Ruby 2.0.0.
Ruby 2.0.0 was not on my system, so I tried to install it using
rvm install 2.0.0
which immediately produced an error.
Checking the appropriate log file showed the following:
Warning: The Command Line Tools for Xcode don't appear to be installed; most ports will likely fail to build.
(Yes, XCode is required (for its compiler), so install it if you haven’t done so already.)
So, XCode CLI first; that was strange as I knew that I’d downloaded the XCode app from the Apple app store recently.
I ran XCode and realized the problem – downloaded but not installed. On first run, XCode opens the Preferences -> Downloads window from which you can select items to, err, download. The Command Line Tools are not selected by default, so click on them and wait for the CLI to be installed.
I then turned to MacPorts and tried to run
sudo port -v selfupdate
but got an error message. I vaguely remembered having a problem with MacPorts last time I tried to install Ruby 2.0, so I decided to try a clean install.
The MacPorts site has a link for users of various flavors of OSX so I ran the one for Mountain Lion and got an ‘Installation Successful’ message.
Just to make sure, I tried
sudo port -v selfupdate
again, and got the message
---> MacPorts base is already the latest version The ports tree has been updated. To upgrade your installed ports, you should run port upgrade outdated
so I ran
port upgrade outdated
as suggested and received a couple of warnings about uninstall being forced for ‘readline’ and ‘freetds’ but got
---> No broken files found.
in the end.
rvm install 2.0.0
then ran without a hitch.
Just to tidy up, I added
to the end of my .bashrc script. If it is not clear, adding this line to the .bashrc script (which runs every time a Terminal window is opened) enables rvm scripts to run by simply typing e.g.,
Looking at the contents of the
~/.rvm/scripts/rvm folder in Finder shows just how many scripts there are available
Then I ran
rvm alias create default 2.0.0
(which is one of the above mentioned scripts) to set Ruby 2.0.0 as the default Ruby version when I open a Terminal window.
To illustrate, when I open a Terminal window and run either Ruby or irb, I get the following:
martin@polaris:~ ruby -v ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0] martin@polaris:~ irb 2.0.0-p247 :001 >
One thing that rvm does not do is create the documentation on an install (see http://rvm.io/rubies/docs). This can be checked by attempting to use ri, e.g:
martin@polaris:~ ri Hash Nothing known about Hash
I fixed this by running
rvm docs generate
However, doing so generated a warning:
Warning! PATH is not properly set up, '/Users/martin/.rvm/gems/ruby-2.0.0-p247/bin' is not at first place, usually this is caused by shell initialization files - check them for 'PATH=...' entries, it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles'
so, once the doc build had finished, I ran
rvm get stable --auto-dotfiles
as suggested, which ran successfully and
printenv showed that the path had been amended for the terminal window with the Ruby files at first place.
Lastly, the process produced information that might often be ignored, so I thought I’d include it here:
# In case of problems: # run and read: rvm notes # read docs: http://rvm.io/ # talk to us: http://webchat.freenode.net/?channels=rvm (http://freenode.net/faq.shtml#plusr) # read cheatsheet: http://cheat.errtheblog.com/s/rvm # watch screencast: http://screencasts.org/episodes/how-to-use-rvm # open a bug report: https://github.com/wayneeseguin/rvm/issues