Friday 9 January 2015

Java is not found on your Linux ? It might be the symlinks in /usr/bin that cause this...

It may happen that you have installed Java on your Linux system but it is not recognized as installed and existing.
Check out in /usr/bin directory these symbolic links:
/usr/bin/java
/usr/bin/javaw
They should be pointing to your Java installation folder's and the executables there. For example:

$ ll /usr/bin/java*
  java -> /etc/alternatives/java
  javaws -> /usr/java/latest/bin/javaws

In this case, the first symbolic link is not updated to the latest or default Java bin folder and this may be causing issues.
Change it to point to:
/usr/java/latest/bin/java

and the final result should be:

$ ll /usr/bin/java*
  java -> /usr/java/latest/bin/java
  javaws -> /usr/java/latest/bin/javaws

In my particular case, I wasn't able to find java on my remote Linux machine via SSH connection through PuTTY and adjusting the symlinks in /usr/bin fixed my problem.


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.