I'm learning rails from different books that use different versions of both ruby and rails. Right now I have ruby 1.87 installed on my Mac OS X Snow Leopard (in /usr/bin), but need to also use ruby 1.9 for a different rails application.
Can anyone tell me how to make this work? I'm new to this, so as many instructions as possible would be greatly appreciated.
3 Answers
There are two major Ruby version managers out there from which you can choose:
rbenvandruby-build- RVM
These allow you to keep multiple versions of Ruby on the same system. Once you've installed a version manager, and installed your own Ruby version, you won't mess with your system's Ruby and its Gems, which is the greatest benefit. No more sudo! No more permissions errors and Gem conflicts.
Which one should I choose?
Both do the same thing, but they follow different philosophies. The choice is up to you.
I personally recommend rbenv for its simplicity. I've been using it for years and it has always worked well.
How do I install them?
If you choose rbenv:
- Follow the all the installation and setup instructions.
- Install
ruby-build - Run
rbenv install x.x.xwherex.x.xis the version (userbenv install --listto see which ones are available - Run
rbenv global x.x.xto change your global Ruby version
If you choose RVM:
- Use the secure installation method
- Read the installation instructions — you probably want the single-user configuration
- Use
rvm list knownto list available Rubies and then runrvm install x.x.xto install a specific version. - Use
rvm use x.x.x --defaultto change your default Ruby
I think rbenv deserves at least its own answer.
There is a constant battle between fans of rbenv and those of RVM but I personally like rbenv a lot more. As the Sam Stephenson (the author) states, rbenv it solely concerned with switching Ruby versions (as opposed to RVM, which does a lot more).
On OS X, it's especially easy to give it a try. Just follow the excellent installation instructions on the Github page (if you have Homebrew installed, it's basically just a brew install rbenv ruby-build).
As for switching Rails versions, I once wrote an article about that which my be of interest for you.
2Assuming you have installed the rbenv ruby version: run,
rbenv initThen;
eval "$(rbenv init - zsh)" To confirm the switched version, run;
which rubyIt should be something like;
/Users/MacbookAir/.rbenv/shims/ruby