How to install Oracle java 7 on ubuntu 12.04

By default ubuntu 12.04 comes with Openjdk. In this article, we can see how to install Oracle java 7 on ubuntu 12.04.

Installing Oracle java 7 on ubuntu 12.04

Step 1 » Check the version of java package installed by issuing the below command
krizna@leela:~$ sudo update-java-alternatives -l
java-1.7.0-openjdk-i386 1051 /usr/lib/jvm/java-1.7.0-openjdk-i386

[OR]
krizna@leela:~$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu3)
OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)

The results shows openjdk is installed on your machine .

Step 2 » Remove openjdk by typing the below command .
krizna@leela:~$ sudo apt-get purge openjdk*
Step 3 » Issue the below command to add webupd8 repository.
krizna@leela:~$sudo add-apt-repository ppa:webupd8team/java
Step 4 » update the repositories
krizna@leela:~$sudo apt-get update
Step 5 » Now install Oracle java7 by issuing the below command.
krizna@leela:~$ sudo apt-get install oracle-java7-installer
Step 6 » That’s it, Now check the version
krizna@leela:~$ java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode)

[OR]
krizna@leela:~$ sudo update-java-alternatives -l
java-7-oracle 1 /usr/lib/jvm/java-7-oracle

Oracle Java7 is installed on ubuntu 12.04.

Troubleshooting

Is you had any problem installing the updated version, just remove all the installed java versions and try installing again.
» Just issue the below command to check the installed java versions.
krizna@leela:~$ sudo update-java-alternatives -l
java-1.7.0-openjdk-i386 1051 /usr/lib/jvm/java-1.7.0-openjdk-i386
java-7-oracle 1 /usr/lib/jvm/java-7-oracle

Here we can see both Openjdk and Oracle java installed, we need to remove both inorder to perform a clean install .
» Issue the below commands one by one to remove other versions of java.
krizna@leela:~$ sudo apt-get purge openjdk*
krizna@leela:~$ sudo apt-get purge icedtea*
krizna@leela:~$ sudo rm /var/lib/dpkg/info/oracle-java7-installer*
krizna@leela:~$ sudo apt-get purge oracle-java7-installer*
krizna@leela:~$ sudo rm /etc/apt/sources.list.d/*java*
Reboot the machine and continue from Step 3 to install Oracle java latest version.

4 Comments

  1. In order to instal oracle java 7, do I really need to uninstall openjdk? Can I keep them both and choose one to be the standard with “update-java-alternatives”?

  2. In order to instal oracle java 7, do I really need to uninstall openjdk? Can I keep them both and choose one to be the standard with “update-java-alternatives”?

Leave a Reply

Your email address will not be published.


*