Wednesday 7 January 2015

Install multiple Java versions on a single Linux machine

It is often the case that you need to have multiple Java versions installed on a single machine. My own issue was that I needed Eclipse to be configured to use several versions of Java (toolbar menu Window -> Preferences -> Java -> Installed JREs) and in order to make them known to Eclipse I first need to have their installation folders.

On a RedHat Linux, once you have a Java installed, then installing a next one is not be possible, the OS will return error that Java was already installed. To workaround you need to do this.

1. Install your first java.
2. Rename its folder located in /usr/java/....
3. Delete the symbolic links "default" and "latest" in that same directory.
4. Uninstall Java from the Applications -> Add/Remove Software (under RedHat) or whichever way it is done on your Linux version.

5. Install the next java the usual way you do it.
This will create a new folder in /usr/java/  and will also create new "default" and "latest" symlinks in that same location.

Uninstalling Java will not remove its folder if you first rename it and then run uninstall, so you will keep it for further work. Switching to another active system java is just done by editing the symlinks "default" and "latest" pointing them to another java folder in /usr/java/...

You may also need to adjust the links in /etc/alternatives/java in order to make java work (be accessible) but this is subject for another post.

No comments:

Post a Comment