Install Sun JDK On Ubuntu 12.04


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:
java -version


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.

How do I install Oracle Java JDK 7?

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Java, Linux and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.