The installation of Sun-Java runtime environment (JRE) can be a tricky thing and yet it is sometimes needed so everything works as it should. In my time I have experienced several cases where the free java openjdk/icedtea alternative has proven to be outdated in a way some pages have failed to show up correctly.
In this post I am going to show you how to install Sun-Java to a Linux system. These instructions are tested with Debian and Mageia 2 so they should apply pretty well to most configurations. The following instructions are tested and working with Firefox and Chromium browsers.
Installing Java
The very first thing you need to do is to download Java so head down to the http://www.java.com/en/download/linux_manual.jsp?locale=en and get the version corresponding your cpu archicture (32-bit or 64-bit).
Download Java using the tar.gz file. Stay away from the rpms eventhough you might be using a rpm distro.
After the download is completed unzip the Java archive and open your terminal (gnome-terminal, lxterminal…) and become a root user (su root or sudo depending on your configuration)
The following steps are needed to be taken after you have become a root user:
mkdir /opt This folder should already be there but in case it is missing this step needs to be performed
cd /opt
mv /home/your_user_name/jre1.7.* .
After these steps Java is found inside /opt. Then you should perform the following steps:
update-alternatives –install /usr/bin/java java /opt/jre1.7.*/bin/java 1065
update-alternatives –install /usr/bin/javac javac /opt/jre1.7.*/bin/javac 1065
update-alternatives –install /usr/bin/jar jar /opt/jre1.7.*/bin/jar 1065
update-alternatives –install /usr/bin/javaws javaws /opt/jre1.7.*/bin/javaws 1065
update-alternatives –config java
NOTE: These steps taken above make sure that Sun-Java is searched from /opt where it actually lives. So in the above it is made sure that the correct Java gets to be used in case you also have icedtea or openjdk installed.
cd /home/your_user_name/.mozilla/plugins
ln -s /opt/jre1.7.0_09/lib/amd64/libnpjp2.so .
Note: The final steps of the process (starting with ln -s) makes a symbolic link between Java and Firefox so that a browser can find Java. Chromium browser seems to be sensitive to a Firefox plugins directory so you only need to link Java once to a .mozilla/plugins directory inside your home folder. If the folder structure is missing create it: mkdir -p /home/your_user_name/.mozilla/plugins
Note: Remember to restart browser(s) so that Java can be used. You can see list of availabe plugins when you write about:plugins to the address bar.
Removing Java
In case you want to remove Java do the following as a root user
cd /opt
dir
rm -rf insert_java_folder_name_here
Note: dir command shows you the folder listing so you can get the name of the actual Java folder from there.
Next remove the libnpjp2.so link from the hidden folder: /home/your_user_name/.mozilla/plugins
And that is it. Now you hopefully have a better understanding on how to install and remove Sun-Java from Linux system’s when needed.