As of August 2011 Java no longer comes part of the default installation. This is due to Oracle retiring the distributor license that allows operating system vendors from providing Java as a package along with their products. This means that Canonical have removed the Java JDK package from it’s partner repositories, thus making it unavailable for installation through this means. The only alternative it seems is to use OpenJDK, but often stability wins over features, and as such I needed a way to install the official Oracle Java JDK opposed to OpenJDK.
The process of install the Oracle Java JDK is quite simple; you only have to download the JDK and JRE from the Oracle website, install them as normal and then inform Ubuntu about the newly installed Java version.
When Java is released it is posted on the main download page. If however there is a need to download an older release of Java, perhaps for building Android from source, then these can be found on the previous releases page.
When you have found the release of Java that you want then download both the JDK and JRE that are compatible with your system; either Linux x86 or Linux x64.
Typically Java would have been installed within a directory owned by the system. Therefore it only makes sense to do the same thing. Through the terminal create a new directory that Java will be installed in.
p flag makes sure that each level of the directory hierarchy is present
and if not creates it too. Then move the JDK and JRE that have been downloaded
in to this directory and then move to this location.
Unix will not let any file be executed unless it has permission to do so.
Therefore to change the permissions of the two installer the
needs to be run with the new permission as arguments.
Extract each of the installers which will essentially install the software, putting relevant files in place.
Informing Ubuntu about Java
Ubuntu needs to know about the new installation of Java in order for it to be
update-alternatives is the command to do this. This command maintains
symbolic links determining default commands. As such this will maintain links
javac commands which were previously installed. Using
update-alternatives allows for multiple installations of a system or software
package to exist and allows for these to be flipped between pretty easily by
setting which alternative system to use.
To tell Ubuntu which Java installation is the default is pretty easy. Since there is currently only one installation on the system then just tell Ubuntu to use that one.
Update the System Path
Now to actually find Java when it is typed into the terminal or invoked through
another application the system wide path needs to be altered to include the
directory in which Java is installed. Open up
/etc/profile with a text editor
(I prefer to use
nano) and add to the bottom the following:
Save and close the text editor. A reboot is required to accommodate for these changes. After the reboot Java should be available for use. To check for this try find the versions of the Java application.
These should return the version numbers of the Java packages that were downloaded and installed. If the numbers differ then something went wrong.