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 17 on Linux systems regardless of the distribution. Oracle JDK 17.0.5 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 17
Download the latest JDK(jdk-17_linux-x64_bin.tar.gz) from this official site:
If you want to download to a remote server or simply prefer the terminal to download the file, use the following command:
Install Oracle JDK 17
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-17-linux-x64_bin.tar.gz file in the jvm directory using this command.
Above command assumes, the JDK filename is jdk-17_linux-x64_bin.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.
Run the ls
command to make sure that the jdk-17.0.5 folder is there. Prior to Java 17, the tar file used to have the minor version in the filename but from Java 17 onwards the tar filename doesn’t have the minor version. Therefore, make sure that you have the expected Java version and change the following commands according to the minor version.
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 folder 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 17.0.5 as the output, you have successfully installed the Oracle JDK on your Linux system. If you have any questions or feedback, please comment below.