Install oracle jdk 7 on linux

Oracle JDK 7 or Sun JDK 7 (previously known) is not bundled together with linux as before. Nowadays the distro use open jdk rather than oracle jdk. However, there are still people who would rather use oracle jdk then open jdk. However, many do not know the process of installing oracle jdk or just don’t remember. This tutorial will show how to install oracle jdk 7 step by step.

Firstly, one will have to download oracle jdk 7 binaries. The binaries are found at:

From here, you can download the one that is required.

Now, open terminal and go to the folder where the jdk is downloaded.

Once there, extract the compressed file. Mine is jdk-7u21-linux-x641.tar.gz, so please replace the names jdk-7u21-linux-x641 and jdk1.7.0_21 with the ones you have. We can extract the folder with the following command.

$ tar zxvf jdk-7u21-linux-x641.tar.gz

Once the files are extracted. Create a directory jvm in /usr/lib, if the folder is not present. The following command will create the folder.

$ sudo mkdir /usr/lib/jvm

Now move the jdk folder to /usr/lib/jvm

$ sudo mv jdk1.7.0_21/ /usr/lib/jvm/

After this, we will have to update system java to oracle jdk 7. For this we use the following commands:

$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_21/bin/java 1065
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_21/bin/javac 1065
$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_21/bin/jar 1065
$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_21/bin/javaws 1065

After this, we set the system java version with the following:

$ sudo update-alternatives --config java

If you already have openJDK, you will see something like this :

  Selection    Path                                            Priority   Status
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/jdk1.7.0_21/bin/java                1065      manual mode

If not, you will only see

  Selection    Path                                            Priority   Status
  0            /usr/lib/jvm/jdk1.7.0_21/bin/java                1065      manual mode

Whatever the result, enter the number under selection of the one you require at the end of the text

Press enter to keep the current choice[*], or type selection number:

and press enter. In the first case, we will have to enter 2 as our value, in the second case we will have to enter 0.

Thus, oracle jdk 7 is installed. To test the installation, you can use the following command :

$ java -version



Add a Comment

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