The on-time release of Java 13 -- along with its new language features and JVM enhancements -- made waves at Oracle Code One 2019 in San Francisco in September.
But of course, you can't take advantage of any of these new features if JDK 13 isn't installed. Let's explore how to install JDK 13 on Ubuntu, and demonstrate how to set JAVA_HOME and the PATH environment variables on your Linux distribution.
Step 1: Download and extract the JDK binaries
You can obtain the AdoptOpenJDK distribution of Java 13 through the Java website. Then, download the 64-bit Linux distribution.
Once the download is complete, it saves a gzip file named openjdk-13_linux-x64_bin.tar.gz into your downloads folder. Extract the contents of this file in the same folder.
Step 2: Move the JDK binaries to /opt/
In the first subfolder of the extracted JDK 13 binaries, there will be a folder named JDK-13. Use the terminal window to move this folder into Ubuntu's /opt directory
jdk13@ubuntu:$ sudo mv jdk-13 /opt/
Step 3: Set JAVA_HOME and PATH in your Ubuntu profile
After you move the binaries to /opt/, the next step is to set the JAVA_HOME and PATH for the JDK 13 install. These variables must be set every time Ubuntu starts. I'd recommend you run a tee command and add them to a script that runs every time a user logs in.
jdk13@ubuntu:$ sudo tee /etc/profile.d/jdk13env.sh <<EOF
When you run tee command, it will create the file with the JAVA_HOME and PATH variable settings, but it won't run the file. To get these variables to take effect, run the file using the source command:
jdk13@ubuntu: $ source /etc/profile.d/jdk13env.sh
Step 4: Echo the newly set JAVA_HOME and PATH variables
Next, validate that you successfully executed the step to set JAVA_HOME and PATH with the echo command.
jdk13@ubuntu:$ echo $JAVA_HOME
jdk13@ubuntu:$ echo $PATH
Step 5: Verify the JDK 13 on Ubuntu installation
With the JDK-13 folder moved to /opt and the step to set JAVA_HOME and the PATH completed, you can validate the JDK 13 install when you run the java –version command. The result should appear as follows:
jdk13@ubuntu:$ java –version
openjdk version "13" 2019-09-17
OpenJDK Runtime Environment (build 13+33)
OpenJDK 64-Bit Server VM (mixed mode, sharing)
Steps to install JDK 13 on Ubuntu and set JAVA_HOME
In summary, the five steps to install JDK 13 on Ubuntu and set JAVA_HOME and the PATH variables are:
- Download and extract the JDK binaries.
- Move the JDK binaries to /opt.
- Set JAVA_HOME and PATH locally and in your Ubuntu profile.
- Echo the newly set JAVA_HOME and PATH
- Run java –version to validate the JDK 13 on Ubuntu installation.
That's all there is to install JDK 13 on an Ubuntu machine and set the JAVA_HOME and PATH variables properly.