Debian update-alternatives
Ruby
Debian sarge comes with ruby 1.8.2 installed, if your like and love ruby on rails, you need ruby 1.8.4 installed. There are a lot of documents about how to install ruby 1.8.4 so i’ll not go into that. I presume you got ruby 1.8.4 installed in /usr/local/bin. What most people i know seem todo is put /usr/local/bin as the first entry in there PATH environment variable. While this works i don’t really think this is a nice solution. Lets do it the Debian way.
$ /usr/sbin/update-alternatives --display ruby
No alternatives for ruby.
Since there is no alternative for ruby setup yet we will need to create one. First lets look at the current installed executable.
$ which ruby
/usr/bin/ruby
$ ruby --version
ruby 1.8.2 (2005-04-11) [i386-linux]
$ /usr/local/bin/ruby --version
ruby 1.8.4 (2005-12-24) [i686-linux]
The default path for the ruby interpeter in our case is /usr/bin/ruby and it’s version 1.8.2 and if we look at my own compiled executable it is at version 1.8.4 the correct version for ruby on rails. So what we want to do now rename /usr/bin/ruby to a new name so we can make room to let /usr/bin/ruby link to the alternatives. The nice thing though is that /usr/bin/ruby is already a symlink in sarge and it points to /usr/bin/ruby1.8 that’s perfect for what we are doing so we can easily remove /usr/bin/ruby symlink and use /usr/bin/ruby1.8 later on.
$ ls -l /usr/bin/ruby
lrwxrwxrwx /usr/bin/ruby -> ruby1.8
$ ls -l /usr/bin/ruby1.8
-rwxr-xr-x /usr/bin/ruby1.8
As you can see we can safely remove the /usr/bin/ruby symlink.
$ sudo rm /usr/bin/ruby
Lets be a good citizen and also take the manpage of ruby into account. The same thing applies, the ruby.1.gz file is a symlink to ruby1.8.1.gz perfect! So let’s remove that symlink as well.
$ ls -l /usr/share/man/man1/ruby*
-rw-r--r-- /usr/share/man/man1/ruby1.8.1.gz
lrwxrwxrwx /usr/share/man/man1/ruby.1.gz -> ruby1.8.1.gz
$ rm /usr/share/man/man1/ruby.1.gz
Allright everything is prepared for the use of the alternative system, lets rock!
sudo /usr/sbin/update-alternatives --install /usr/bin/ruby \
ruby /usr/bin/ruby1.8 300 --slave /usr/share/man/man1/ruby.1.gz \
ruby.1.gz /usr/share/man/man1/ruby1.8.1.gz
This wil have create /usr/bin/ruby and /usr/share/man/man1/ruby.1.gz which are the symlinks we just removed and both of these files will be linked to the alternative file.
$ ls -l /usr/bin/ruby
lrwxrwxrwx /usr/bin/ruby -> /etc/alternatives/ruby
$ ls -l /usr/share/man/man1/ruby.1.gz
lrwxrwxrwx /usr/share/man/man1/ruby.1.gz -> /etc/alternatives/ruby.1.gz
$ ls -l /etc/alternatives/ruby
lrwxrwxrwx /etc/alternatives/ruby -> /usr/bin/ruby1.8
$ ls -l /etc/alternatives/ruby.1.gz
lrwxrwxrwx /etc/alternatives/ruby.1.gz -> /usr/share/man/man1/ruby1.8.1.gz
Almost done, as an extra security measure lets look at the output of –display, just to make sure everything is looking good.
$ /usr/sbin/update-alternatives --display ruby
ruby - status is auto.
link currently points to /usr/bin/ruby1.8
/usr/bin/ruby1.8 - priority 300
slave ruby.1.gz: /usr/share/man/man1/ruby1.8.1.gz
Current `best' version is /usr/bin/ruby1.8.
$ ruby --version
ruby 1.8.2 (2005-04-11) [i386-linux]
It correctly added the alternative file, also take note that the slave file ruby.1.gz is also currently configured. When checking for the ruby interpeter version we see that we’re currently running the expected 1.8.2 version. Now for the final part lets add the ruby 1.8.4 interpeter with a higher priority so it takes precedence when we are in auto mode.
$ sudo /usr/sbin/update-alternatives --install /usr/bin/ruby \
ruby /usr/local/bin/ruby 314 --slave /usr/share/man/man1/ruby.1.gz \
ruby.1.gz /usr/local/share/man/man1/ruby.1
That should be it, lets look at the –display output.
$ /usr/sbin/update-alternatives --display ruby
ruby - status is auto.
link currently points to /usr/local/bin/ruby
/usr/bin/ruby1.8 - priority 300
slave ruby.1.gz: /usr/share/man/man1/ruby1.8.1.gz
/usr/local/bin/ruby - priority 314
slave ruby.1.gz: /usr/local/share/man/man1/ruby.1
Current `best' version is /usr/local/bin/ruby.
steven@rails:~$ ruby --version
ruby 1.8.4 (2005-12-24) [i686-linux]
Perfect, because we gave a high priority to /usr/local/bin/ruby it automatically picks this version as you can see. Well to wrap it up lets change it back to the 1.8.2 ruby interpeter see if that still works for us.
$ sudo update-alternatives --config ruby
There are 2 alternatives which provide `ruby'.
Selection Alternative
-----------------------------------------------
1 /usr/bin/ruby1.8
*+ 2 /usr/local/bin/ruby
Press enter to keep the default[*], or type selection number: 1
Using `/usr/bin/ruby1.8' to provide `ruby'.
steven@rails:~$ ruby --version
ruby 1.8.2 (2005-04-11) [i386-linux]
Great it works!
There are some final things to keep in mind. When change an alternative via –config parameter this particular alternative goes from auto into manual mode. You can set this back to auto mode using the –auto option. Let me demonstrate.
$ ruby --version
ruby 1.8.2 (2005-04-11) [i386-linux]
$ /usr/sbin/update-alternatives --display ruby
ruby - status is manual.
link currently points to /usr/bin/ruby1.8
/usr/bin/ruby1.8 - priority 300
slave ruby.1.gz: /usr/share/man/man1/ruby1.8.1.gz
/usr/local/bin/ruby - priority 314
slave ruby.1.gz: /usr/local/share/man/man1/ruby.1
Current `best' version is /usr/local/bin/ruby.
$ sudo update-alternatives --auto ruby
$ /usr/sbin/update-alternatives --display ruby
ruby - status is auto.
link currently points to /usr/local/bin/ruby
/usr/bin/ruby1.8 - priority 300
slave ruby.1.gz: /usr/share/man/man1/ruby1.8.1.gz
/usr/local/bin/ruby - priority 314
slave ruby.1.gz: /usr/local/share/man/man1/ruby.1
Current `best' version is /usr/local/bin/ruby.
$ ruby --version
ruby 1.8.4 (2005-12-24) [i686-linux]
If you look at the ruby status, it goes from manual to auto. Also pay attention to the line saying “link currently points to…” since /usr/local/bin/ruby has a higher priority it automatically gets linked to this version.
As you can see the Debian alternative system keeps your system clean and its really easy to mantain. There are already a lot of preconfigured alternatives on your debian system so be sure to check out the /etc/alternatives directory, or try running update-alternatives –all this will go through all the configuration currently on your system.
Pages: 1 2

