Even though OpenJDK is available in most of the official Linux repositories, some applications require Oracle Java Development Kit for better performance. This article shows you how to manually install Oracle JDK 8 on Linux systems regardless of the distribution. Oracle JDK 1.8.0_351 is used in this article to demonstrate the installation. In the provided commands, replace the version-specific paths and file names according to your downloaded version.
If you came here for a different version of Java, we got you covered. Here is the list of articles on how to install different versions of the Oracle Java Development Kit on Linux:
- Install Oracle Java Development Kit 8 on Linux
- Install Oracle Java Development Kit 11 on Linux
- Install Oracle Java Development Kit 17 on Linux
- Install Oracle Java Development Kit 19 on Linux
- Install The Latest Oracle Java Development Kit on Linux
Download Oracle JDK 8
Download the latest JDK(jdk-8u351-linux-x64.tar.gz) from this official site:
Install Oracle JDK 8
Step 1:
Open the terminal (Ctrl + Alt + T) and enter the following command to create the parent directory to deploy the JDK. If the directory already exists, you can ignore this command and move to the next step.
Step 2:
Enter the following command to change the directory.
Step 3:
Extract the jdk-8u351-linux-x64.tar.gz file in the jvm directory using this command.
The above command assumes the JDK filename is jdk-8u351-linux-x64.tar.gz and it is located in the ~/Downloads folder. If your downloaded file is in any other location, change the command according to your path.
Setup The Environment
Step 1:
Enter the following command to open the environment variables file. According to your personal preference, you can choose any text editor instead of nano.
Step 2:
In the opened file, add the following bin folders to the existing PATH variable. Note that the PATH variables must be separated by a colon.
Append the following environment variable to the end of the file.
A sample environment file before making these changes would look like the following:
The same file after making the changes should look like this:
Save the changes and close the editor. If you are using nano as in this article, the shortcut to save the changes is Ctrl + O; the shortcut to close nano is Ctrl + X. To learn more about setting environment variables and/or setting the environment variable without root privilege, check How to Set Environment Variables in Linux.
Step 3:
Sometimes an existing JDK installation might have a shortcut added to the /usr/bin directory. Therefore setting the PATH environment variable alone may not change the default Java compiler and runtime. To update these alternative shortcuts, run the following commands:
Step 4:
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.
Step 5:
Restart the computer (or just log out and log in) and open a new terminal.
Step 6:
Enter the following command.
If you get the Java version 1.8.0_351 as the output, you have successfully installed the Oracle JDK on your Linux system. If you have any questions or feedback, please comment below.