Monday, November 1, 2010

Ubuntu 10.04 upgrade on Acer netbook: Ruby Version Manager and Ruby 1.9.2

Previous: Ubuntu 10.04 upgrade on Acer netbook: Adobe Flash Player

The things I had done so far on the Acer did not tell me much about how 10.04 would play on the Toshiba. I was leery of 5100 AGN support, and the Adobe Flash Player for 64-bit Linux was still in a pre-release state.

Installing software development tools ought to be less problematic than all that. I found that many people were singing the praises of Ruby Version Manager (rvm). It gives you the ability to run multiple releases of ruby on the same machine without having to uninstall and install different releases. It sounded useful, and most of the comments online were very positive.

Following advice on http://web2linux.com/installing-rails-3-on-ubuntu-10-04-lucid-lynx/, I began by installing prerequisites to rvm and ruby:
apt-get install
curl
git-core
build-essential
zlib1g-dev
libssl-dev
libreadline5-dev
I then proceeded to make a series of noob mistakes, and after cleaning off various partial and incorrect installs, this is how I got rvm working. The official installation instructions at http://rvm.beginrescueend.com/rvm/install/ are pretty good, but are not exactly right.

The installation instructions mention three options — install as user, install as root, and system-wide install. I wanted to install as user so that everything would be under /home. That makes it easier to upgrade Ubuntu, since I can restore /home from a backup after doing the basic install. That was my plan for the Toshiba, anyway. For the Acer, I just blew everything away and installed fresh.

First step was to use curl to get the latest version of rvm from head:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
This step appeared to work. The author, Wayne Seguin, kindly included the following advice in the console output: "Be sure to get head often as rvm development happens fast." Sound advice.

They suggest running
rvm notes
to install dependencies, but in fact it only displays a description of dependencies.

They say you must not have any returns in .bashrc. They specifically call out a line in Unbuntu's .bashrc:
[ -z "$PS1" ] && return
and they recommend wrapping this in an if structure so that rvm will work correctly. I found that after completing the rest of the installation steps, rvm never worked. It turned out that this change is required only for the installation process, and once rvm has been installed you should reinstate the original statement. I changed it to
if [[ -n "$PS1" ]] ; then
return
fi
and afterwards changed it back to
[ -z "$PS1" ] & return
The installation instructions also say to put this line at the end of .bashrc:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
They then say you have to run
source ~/.rvm/scripts/rvm
the first time you use rvm. In fact, you have to run this command every time you want to use rvm. I added the source command to the end of .bashrc, and rvm now works properly.

The other thing to be aware of is that the installation instructions say you run
type rvm | head -n1
and it should display
rvm is a function
Then, you run the source command for the first time. In fact, that results in
rvm is hashed (/usr/local/bin/rvm)
You have to run the source command first, and then rvm will be a function.

Finally rvm was working. I used it to install ruby 1.9.2:
rvm install 1.9.2
and then to make 1.9.2 the default version of ruby (as far as rvm was concerned, anyway):
rvm --default 1.9.2
Good news: It installed rubygems automatically.

Now I could install other gems and run ruby to my heart's content, but only when running as 'user'.

Next: Ubuntu 10.04 upgrade on Acer netbook: Instiki migration

No comments:

Post a Comment