Install Oracle JDK in Ubuntu

Oracle Java is the proprietary, reference implementation for Java. This is no longer currently available in a supported Ubuntu repository. This article shows you the way to manually install the latest Oracle Java Development Kit (Oracle JDK) in Ubuntu.


Note: This article uses JDK8_Update_$java_update_no to demonstrate the installation. In the provided commands, replace the version specific paths and file names to your downloaded version.

Step 1:
Download the latest JDK(jdk-Xuxx-linux-xXX.tar.gz) from this official link.

Step 2:
Open the terminal (Ctrl + Alt + T) and enter the following command.
sudo mkdir /usr/lib/jvm
If the /usr/lib/jvm folder does not exist, this command will create the directory. If you already have this folder, you can ignore this step and move to next step.

Step 3:
Enter the following command to change the directory.
cd /usr/lib/jvm

Step 4:
Extract the jdk-Xuxx-linux-xXX.tar.gz file in that directory using this command.
sudo tar -xvzf ~/Downloads/jdk-8u$java_update_no-linux-x64.tar.gz
According to this command, the JDK filename is jdk-8u$java_update_no-linux-x64.tar.gz and which is located in the ~/Downloads folder. If your downloaded file is in any other location, change the command according to your path.

Step 5:
Enter the following command to open the environment variables file.
sudo gedit /etc/environment

Step 6:
In the opened file, add the following bin folders to the existing PATH variable.
/usr/lib/jvm/$java_version/bin
/usr/lib/jvm/$java_version/db/bin
/usr/lib/jvm/$java_version/jre/bin
The PATH variables have to be separated by semicolon.
Notice that the installed JDK version is 1.8 update $java_update_no. Depending on your JDK version, the paths can be different.
Add the following environment variables at the end of the file.
J2SDKDIR="/usr/lib/jvm/$java_version"
J2REDIR="/usr/lib/jvm/$java_version/jre"
JAVA_HOME="/usr/lib/jvm/$java_version"
DERBY_HOME="/usr/lib/jvm/$java_version/db"

The environment file before the modification:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
The environment file after the modification:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/$java_version/bin:/usr/lib/jvm/$java_version/db/bin:/usr/lib/jvm/$java_version/jre/bin"
J2SDKDIR="/usr/lib/jvm/$java_version"
J2REDIR="/usr/lib/jvm/$java_version/jre"
JAVA_HOME="/usr/lib/jvm/$java_version"
DERBY_HOME="/usr/lib/jvm/$java_version/db"

Save the changes and close the gedit.

Step 7:
Enter the following commands to inform the Ubuntu about the Java's location. Depending on your JDK version, the paths can be different.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/$java_version/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/$java_version/bin/javac" 0
sudo update-alternatives --set java /usr/lib/jvm/$java_version/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/$java_version/bin/javac

Step 8:
To verify the setup enter the following commands and make sure that they print the location of java and javac as you have provided in the previous step.
update-alternatives --list java
update-alternatives --list javac

Step 9:
Restart the computer (or just log-out and login) and open the terminal again.

Step 10:
Enter the following command.
java -version

If you get the installed Java version as the output, you have successfully installed the Oracle JDK in your system.
Previous
Next Post »

1 comments:

Write comments
wizard_romania
AUTHOR
September 16, 2016 at 3:53 PM delete

Not a bad idea to also update default-java sym link:

sudo ln -sfn /usr/lib/jvm/jdk1.8.0_102/ /usr/lib/jvm/default-java

Reply
avatar

Contact Form

Name

Email *

Message *