This a modernized update to a previous post I wrote on here, about doing Ruby 1.9 & Rails 3.
There are two ways you can go with Ruby, right now. Canonical is finally starting to get with the program with Ruby versions, and there is a Ruby 2.0 package, though that is lagging slightly on minor versions. Here’s a comparison of my RVM version and the Universe version.
aaron@naegleria:~$ ruby -v ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] aaron@naegleria:~$ /usr/bin/ruby -v ruby 2.0.0p384 (2014-01-12) [x86_64-linux-gnu]
Packages are nice, and a safe way to go. If you want to keep things simple and don’t mind being a little bit behind the curve, just stick with the package.
But since this is a blog, and you’re a reader and don’t have to make tough decisions, LET’S GET CRAZY AND DO RVM! I have heard that “rbenv” is the new hotness, though I have not yet used it. RVM still works and works well, so I’m going to cover that, here.
Getting started with RVM is pretty simple. There’s a way to do Ruby/Rails installation automatically (using the “–ruby” and “–rails” flags), but let’s do it step-by-step to make it a little less magical. Start out by installing RVM:
aaron@naegleria:~$ curl -sSL https://get.rvm.io | bash -s stable ...#stuff happens#... aaron@naegleria:~$ echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
This will do stuff. It doesn’t take long. The second line will append the RVM activation script into your .bash_profile, so that it is available in your Term session. After that, you will either need to do [cc]source ~/.bashr_profile[/cc], or just close the Terminal and open a new session. You should be able to do this, now:
aaron@naegleria:~$ rvm version rvm 1.25.28 (stable) by Wayne E. Seguin <firstname.lastname@example.org>, Michal Papis <email@example.com> [https://rvm.io/] aaron@naegleria:~$
Now you can install one (OR MORE!) Ruby versions. Install all the ones you want, you can switch between them easily enough. For this example, we’re just going to install the latest Ruby, “ruby-head”:
aaron@naegleria:~$ rvm install ruby-head ...#stuff happens#... aaron@naegleria:~$ rvm list rvm rubies = ruby-2.1-head [ x86_64 ] # => - current # =* - current && default # * - default aaron@naegleria:~$ rvm use ruby-2.1-head --default Using /home/aaron/.rvm/gems/ruby-2.1-head aaron@naegleria:~$ rvm list rvm rubies =* ruby-2.1-head [ x86_64 ] # => - current # =* - current && default # * - default aaron@naegleria:~$
Whatever other Rubies you want to install, you can switch with a simple
rvm use RUBY-VER, where “RUBY-VER” is the item in the list (ie. ruby-2.1-head).
If you’re having issues here, check out the debugging guide on RVM’s main site.
RubyGems will handle all the heavy lifting from here on out. The RVM installation should include the RubyGems installation by default. If it doesn’t, check the RVM RubyGems guide.
Let’s install Rails 4.
aaron@naegleria:~$ gem install rails -v 4.1.0 ...#stuff happens#... aaron@naegleria:~$ rails new APPNAME
One thing we can do now, with new Rails hotness, is to specify which version of Ruby we want right in the Gemfile. This will signal to RVM to switch to the correct Ruby version as soon as we cd into that App. Within APPNAME, edit your Gemfile and add this to the very top:
source 'https://rubygems.org' ruby '2.1.2'
Now check it out:
aaron@naegleria:~$ rvm use ruby-2.0.0 Using /home/aaron/.rvm/gems/ruby-2.0.0-p481 aaron@naegleria:~$ ruby -v ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux] aaron@naegleria:~$ cd APPNAME aaron@naegleria:~/APPNAME/$ ruby -v ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] aaron@naegleria:~/APPNAME/$