FINALLY! SOME UPDATES! This website is being reconstructed. Some content will go away soon. If you want to see my new stuff, visit my github: https://github.com/jrcharney/.

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.

sudo apt-get install ruby
Just like everything else.

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.

sudo apt-get remove ruby
No harm. No foul.

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.)

The Ruby download page list some third party tools for installing Ruby. The most popular of these third party tools is RVM, the Ruby Version Manager. RVM makes installing Ruby and Rails very easy.

curl -l https://get.rvm.io | bash -s stable --ruby
Easy!

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.

source ~/.rvm/scripts/rvm
Easy...but Hey, shouldn't I have done all this with a sudo?

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.

 * WARNING: You have '~/.profile' file, you might want to load it,
     to do that add the following line to '/home/jrcharney/.bash_profile':

           source ~/.profile
Ugh! why is the text dark red?

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.

echo "source ~/.profile" >> ~/.bash_profile
Append a line to .bash_profile

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.

~$ rvm list
Warning! PATH is not properly set up, '/home/jrcharney/.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',
         to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p247'.

rvm rubies

=* ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
#  * - default

"Me first!"

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.

~$ cat .bash_profile >> .profile
~$ rm .bash_profile
This is what Should have happened.

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.

~$ rvm install jruby
You got Java in my Ruby!

Or you can see a list of installed .gems using 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.

gem install rails
That's it? Why can't everything else be this 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.

Twitter

Tags

Under Construction