Centos Alternatives

From Biowiki
Revision as of 14:51, 25 February 2008 by Lars Barquist (talk | contribs) (Imported from TWiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Centos has a neat application for switching between alternative software packages, called 'alternatives' cleverly enough. Here's a run down using a new Sun JDK install at /nfs/src/jdk1.6.0_04/jre/bin/java as an example, since googling "centos alternatives" is annoying at best:

1) Install your application wherever you want, /nfs/src/jdk1.6.0_04/jre/bin/java in this case

2) (Note: you should be root or equiv for the following) Run the command:

/usr/sbin/alternatives --install /usr/bin/java java /nfs/src/jdk1.6.0_04/jre/bin/java 10 --slave /usr/bin/rmiregistry rmiregistry /nfs/src/jdk1.6.0_04/bin/rmiregistry --slave /usr/lib/jvm/jre jre /nfs/src/jdk1.6.0_04/jre

The --install option creates a symlink at /usr/bin/java (if an alternatives symlink doesn't already exist), and creates an alternatives profile named 'java' (or modifies the old one to include the new application) for the application located at /nfs/src/jdk1.6.0_04/jre/bin/java. The fourth argument is a priority, I believe it indicates which installation is "best", and there's some command mode for selecting the "best" rather than the default, but it's probably safe to ignore.

--slave creates symlinks and profile linked to this particular java installation, so if there are eg directories with libraries the application needs, and these differ between versions, they will be switched on the fly by alternatives as well. This is probably the most useful part of alternatives vs. normal symlinking, you only need to worry about path-y stuff on the initial install, and not with each switch.

3) Run:

/usr/sbin/alternatives --config java

This will print something like:

There are 2 programs which provide 'java'.

  Selection	 Command
-----------------------------------------------
*  1			  /usr/lib/jvm/jre-1.4.2-gcj/bin/java
 + 2			  /nfs/src/jdk1.6.0_04/jre/bin/java

Enter to keep the current selection[+], or type selection number: 

Now you can switch back and forth between your various installs on a whim. Enjoy!

Other potentially useful commands:

  • /usr/sbin/alternatives --display java prints out information on the applications in profile 'java', including any slaved symlinks

-- Lars Barquist - 25 Feb 2008