As a new forum member, I've seen quite a lot of threads asking how to install the latest Sun java JREs and JDKs. Sometimes instructions are given, other times not. The official help documentation doesn't really give instructions on installing Sun Java, without using the package from the package repositories.
So I am writing this to provide a one-stop shop for those wanting to install Sun's JRE or JDK on Ubuntu. This how-to works with both 6.06 and 6.10 versions of Ubuntu, and with JRE 1.5.0_x and 1.6.0, and JDK 1.6 SE. It also assumes that you run 32-bit x86 architecture systems. Following these steps will accomplish:
1. JRE installation into your /opt directory, and plugin installation for Firefox.
2. JDK installation into your /opt for Java programming.
3. Setting correct references in /usr/bin for command-line invocation of Java tools.
Step One - initial download
Download the linux binaries for Java from Sun's official Java website.
Place the downloaded files in your home folder. For example: /home/samjh/
Step Two - installing the JRE
Open Nautilus (the default Gnome graphical file manager). Navigate to your downloaded JRE binary. Right-click on the file, select Properties. A properties dialog box will open up. Select the Permissions tab, and tick the box that says to allow the file to run as an executable. Click OK.
Double-click on the downloaded JRE binary. A dialog box will appear, asking how to open it. Select "Run in Terminal" (do not just select "Run"). A terminal window will open with the license agreement. Keep pressing enter to scroll through the agreement (it takes several seconds if you hold it down). It will ask if you accept the agreement, so type "y" without quotation marks, and press enter.
The file will unpack itself. When it finishes, close the terminal window if it doesn't close automatically.
Step Three - moving the JRE directory to /opt
Open your terminal.
Navigate to the directory where the unpacked JRE folder is (the folder name should be jre1.5.0_x or jre1.6.0). If you followed the instructions above, this will be in /home/yourusername/
Type this command (substitute yourjredirectoryname with the actual directory name):
sudo cp -r ./yourjredirectoryname /opt
sudo cp -r ./jre1.6.0 /opt
It will ask for your password. Type it in and press enter, and the command will copy your JRE directory and its contents to the /opt directory.
Step Four - create symbolic links in user binary directory
Stay in your terminal window. Type the following command to navigate to usr/bin:
Then type these commands to remove existing java symbolic links (Do NOT type these all on the one line! Use separate lines for each!):
Don't worry if it tells you the files cannot be found. Ignore them, because it just means that your existing Java installation didn't create the links.
sudo rm ./java
sudo rm ./java_vm
sudo rm ./javaws
Then type these commands to add new symbolic links (substitute yourjredirectoryname with your actual JRE directory name):
sudo ln -s /opt/yourjredirectoryname/bin/java ./java
sudo ln -s /opt/yourjredirectoryname/bin/javaws ./javaws
sudo ln -s /opt/yourjredirectoryname/bin/java_vm ./java_vm
sudo ln -s /opt/jre1.6.0/bin/java ./java
Step Five - create symbolic link to Java plugin for Firefox
First, use Nautilus, and navigate to /opt/yourjredirectoryname/plugin/i386/ns7 directory. Right-click on the libjavaplugin_oji.so file, and select Properties, then select Permissions in the dialog window. Check to see that the owner of the file is you (it should say your user name).
If it says the owner is root, then the plugin will not work for anyone other than root. You need to type this in terminal to get it to work for you:
Now, use the cd command in your terminal to navigate to the /home/yourusername/.mozilla/plugins directory. Substitute yourusername with your actual user name, and take care to include the full-top (".") in .mozilla.
sudo chmod 755 libjavaplugin_oji.so
(If the plugins directory doesn't exist, then create one. Feisty Fawn users have reported that the plugin goes to /usr/lib/firefox/plugins instead, so please place your plugin link to that directory instead of the one I've specified.)
Now, command your terminal with this proclamation:
Close any existing Firefox sessions. Re-start Firefox.
ln -s /opt/yourjredirectoryname/plugin/i386/ns7/libjavaplugin_oji.so ./
Go to http://www.java.com/en/download/installed.jsp and click on the "Verify Installation" button. The next page will check your installation for several seconds. If it then says "We detected your Java environment as follows", then your installation of the plugin was a success.
Now go make love, have a shower, and return when well-rested. You have successfully installed the Java Runtime Environment.
Step Six - install the JDK
Repeat Steps Two and Three, but use your downloaded JDK binary instead of the JRE one.
Step Seven - linking the JDK tools
Similar to Step Four.
Navigate to /usr/bin using your terminal, and type the following:
This will allow the javac command to be run without having to specify the path every time.
sudo ln -s /opt/yourjdkdirectoryname/bin/javac ./
Optionally you can also run this:
But Ubuntu already ships with fastjar already linked, which should be a good enough jar packer. So linking jar is entirely optional. I personally use fastjar.
sudo ln -s /opt/yourjdkdirectoryname/bin/jar ./
Now go make love, have a shower, and return when well-rested. You have successfully installed the Java Development Kit.
Uninstalling JRE and/or JDK
If you are uninstalling the JRE or JDK, you can do it using the terminal like this (where yourjavadirectoryname is the directory you want to remove):
Then navigate to /usr/bin, and do this for JRE...
sudo rm -r ./yourjavadirectoryname
...or this for JDK...
sudo rm ./java
sudo rm ./javaws
sudo rm ./java_vm
...note that you won't need to remove the link for jar if you didn't make a link during installation.
sudo rm ./javac
sudo rm ./jar
To remove the firefox plugin, do this:
Here endeth this newbie's guide to installing/uninstalling Sun Java, the non-packaged way.
Rationale for installing separate JRE and JDK:
I am a Java programmer. As such, I have occasionally need to use multiple JDK and even multiple JREs for compatibility testing. Separating your JRE and JDK installation will allow you to use separate Java build and test environments without affecting your ability to run Java software or applets. Also, the loss of the JDK will not equal losing JRE functionality, so you have more flexibility over your Java installation.
DISCLAIMER: Your computer configuration may not be fully compatible with the instructions posted above. The instructions are provided as-is, without any warranty or promise, express or implied, against direct or indirect damages of any kind. Use these instructions at your own risk.