Ubuntu had removed the latest version of Java from the repository and uses the OpenJDK instead. Whilst this is fine for personal use but for development purposes the development should be done against the runtime environment which is usually Oracle’s JRE.
Download the SDK from the Oracle website. In this post the example file is jdk-7u2-linux-x64.tar.gz.
Extract the zipped file:
tar -xvf jdk-7u2-linux-x64.tar.gz
Move the extracted files to the system directory:
sudo mv ./jdk1.7.0_02 /usr/lib/jvm/jdk1.7.0
Update the links for the java runtime, compiler and virtual machine:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
Select the default version of Java to use to run programs:
sudo update-alternatives --config java
Follow the instructions on screen.
Select the same for the compiler and virtual machines:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
Run the following command to check the new version is selected:
It’s annoying having to manually do this but it works. It does mean any updates will have to be performed in the same way.