Install Oracle JDK 11 on Linux

Even though OpenJDK is available in Linux repositories, some applications strictly require Oracle Java Development Kit. This article shows you how to manually install Oracle JDK 11 on your Linux system. This article uses JDK 11$java_update_no to demonstrate the installation. In the provided commands, replace the version specific paths and file names according to your downloaded version.

Oracle JDK 12 has been released
To install the latest Oracle JDK, please visit Install the latest Oracle JDK on Linux.

Install Oracle JDK 11 on Linux

Step 1:
Download the latest JDK(jdk-11$java_update_no_linux-x64_bin.tar.gz) from the official site.




If you want to download to a remote server or if you simply prefer wget, use the command given in this StackOverflow answer: Downloading JDK

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 the 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-11$java_update_no_linux-x64_bin.tar.gz
According to this command, the JDK filename is jdk-11$java_update_no_linux-x64_bin.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 nano /etc/environment

According to your personal preference, you can choose any text editors instead of nano.

Step 6:
In the opened file, add the following bin folder to the existing PATH variable.
/usr/lib/jvm/$java_version/bin
The PATH variables must be separated by semicolon.

Add the following environment variables at the end of the file.
JAVA_HOME="/usr/lib/jvm/$java_version"

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"
JAVA_HOME="/usr/lib/jvm/$java_version"

Save the changes and close nano (Ctrl + O, Ctrl + X).

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 »

12 comments

Write comments
jjmkay
AUTHOR
December 10, 2017 at 12:38 AM delete

did not update /usr/lib/jvm/default-java/bin/java.
update-alternatives --display java
java - manual mode
link best version is /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
link currently points to /usr/lib/jvm/jdk-9.0.1/bin/java
link java is /usr/bin/java
slave java.1.gz is /usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1081
slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/jdk-9.0.1/bin/java - priority 0

Reply
avatar
Brian Gallo Añano
AUTHOR
January 21, 2019 at 8:32 PM delete

The installation failed. It ended with this:

bash: /usr/bin/java: cannot execute binary file: Exec format error

Reply
avatar
Gobinath
AUTHOR
January 23, 2019 at 1:46 AM delete

Did you follow Step 7 and made sure the correct Java is selected in Step 8? If so, please check your operating system architecture. It should be 64 bit to install 64bit Java.

Reply
avatar
masquerade817
AUTHOR
March 10, 2019 at 12:34 AM delete

Worked perfectly for me. Thanks! :)

Reply
avatar
Dewa Mahendra
AUTHOR
March 13, 2019 at 2:42 PM delete

thank's it works....

Reply
avatar
Erialdo
AUTHOR
March 25, 2019 at 8:40 PM delete

Hello,

I followed your instructions and worked perfect. Except I have a few questions. Before looking at this article I installed the openjdk version. I am saying this because when I look the path of other java tools (eg. jar, jarsigner) it traced back to the openjdk folder. I want to know, in the future, are there gonna be any problem with this? Of course in case I use these tools.

I don't know if I explained myself clear enough ':-).

Reply
avatar
Gobinath
AUTHOR
March 25, 2019 at 10:26 PM delete

Hi,
There is nothing wrong with having OpenJDK. /usr/lib/jvm is used as the parent for all JDK installations. Suppose you also installed Oracle JDK 8, you will find it in the same folder. I don't find any issues with using tools from both Oracle JDK and Open JDK. You are fine with your current setup.

Reply
avatar
Alex Matos
AUTHOR
April 9, 2019 at 5:22 AM delete

Thanks!!

Reply
avatar
uverkube MC
AUTHOR
May 12, 2019 at 10:42 AM delete

I have jdk8 .0.212 installed in my Ubuntu PC, can I install another version of jdk like jdk11 this way?

Reply
avatar
Gobinath
AUTHOR
May 14, 2019 at 1:05 AM delete

Yes you can but if you prefer to use JDK 8 as the default JDK, do not follow step 5-10.

Reply
avatar
Laura Santos Guerrero
AUTHOR
May 14, 2019 at 9:06 AM delete

Hi, I've follow the tutorial until step 7, but, when i run the first command, this appears: update-alternatives: error: alternative path /usr/lib/jvm/jdk-11/bin/java doesn't exist

I don't know whats wrong.

Reply
avatar
Gobinath
AUTHOR
May 15, 2019 at 2:35 AM delete

Hi, Please share the output of the following command:

ls /usr/lib/jvm

Reply
avatar

Contact Form

Name

Email *

Message *