October 29, 2013
Installing Ruby the Right Way
I upgraded to Ubuntu 13.10 (Saucey Salamander) yesterday and have been working on making some changes to how I use my computer. As much as my love-hate relationship of Ubuntu Unity continues, and as much as I've been moving towards using Lubuntu (Ubuntu that uses LXDE as the Desktop Environment), it is important to remember that when you use a distribution's software, they generally build it so that it works as stable as possible with the current distro. This means, instead of installing the latest version of a software from source where things can go wrong if you don't have something else that is installed, they give you the stable version which is older than any new version.
Such is the case when you are trying to install new software that you want to actually be new software, you have to chose between compiling from the lastest source which could still be a beta version or installing the stable binary from the distro.
For Ruby, the worse thing you can do is install Ruby on Ubuntu like this.
Assuming you haven't installed anything that is dependent on the Ubuntu version (which is still stuck at version 1.9.3), you can fix this foolish mistake by uninstalling their version of Ruby.
Having undone such a foolish mistake, you can now install Ruby the right way. (Note: I have reason to believe this "ruby" is a meta package. So even if you did remove it, it probably won't matter since RVM handle multiple ruby versions. Besides, there is quite a bit of other stuff that uses Ubuntu's Ruby.)
Running this will execute RVM to install the various software and a few common Ruby Gems (
.gem) packages needed to run the latest version of Ruby. However, it won't take effect in the current shell window that you are using until you run the following command.
Good point, figcaption. As I was writing this, I made the mistake of not using
sudo, but this may have been a good mistake for the purpose of say installing the latest version of Ruby, JRuby, or Rails for your website. Theoretically this could work. Rather than wait for the server admins to update this software, you can start using it right away. This is something I hope to make possible here so that next month I can swap out PHP for Ruby.
Another thing that caught my attention was this text while running the RVM install command.
This seems to be something that Ubuntu users need to do so they don't have to run that previous command I mentioned, which you'll have to run every time unless you do the following.
Oh, but there is still a couple problems with doing this. You still need to run
source ~/bash_profile unless you want to restart the machine and RVM likes to be the first thing listed in the
PATH variable. Here's what happens when you run a
rvm command using that previous figure.
So what seems like a better plan? Doing the opposite. In fact, load the contents from
~/.bash_profile to then end of
~/.profile Also we will need to get rid of
~./bash_profile or else
~/.profile will not load.
You may notice that when you open another shell, your still using the unedited path. I'm pretty sure that will change upon system restart. But If you're not interested in waiting for the machine to start over, you can always run
source ~/.profile. When you do this, you will notice that the RVM paths is now paths are now prepended to the
$PATH and instead of
which ruby pointing to Ubuntu's Ruby at
/usr/bin/ruby it points to RVM's Ruby at
~/.rvm/rubies/ruby-2.0.0-p247/bin/ruby. You'll notice the difference when you run
ruby -v and see the version number is 2.0.0 instead of 1.9.3 or 1.8.7
From here on, if you want to install other major gems like JRuby or Rails, you can use RVM like this.
Or you can see a list of installed
gem list or
rvm list. In fact, I recommend using
gem for this task. Be sure to check that you use
which gem to make sure that RVM's gem is used.
Speaking of Gems, the recommended method of installing anything else Ruby related should be with Gem. There is a whole website full of Ruby Gems to download, but the big three are Ruby, JRuby, and Ruby on Rails.
To demonstrate, let's install Ruby on Rails. This process is so easy.
It takes a little while for it to start up. Probably because
.gem installation isn't as verbose as installing from source. It also installs 27 gems in the process.
And that's it. I look forward to completing this task on this website in the near future.