Install Oracle Java Development Kit (JDK) 10 on Linux Mint 19

Install Oracle Java Development Kit (JDK) 10 on Linux Mint 19
In this article, I will show you how to install Oracle JDK 10 on Linux Mint 19. Let’s get started.

Downloading Oracle JDK 10:

First go to the official website of Oracle Java Development Kit (JDK) at http://www.oracle.com/technetwork/java/javase/downloads/index.html and click on Java Platform (JDK) 10 download link as marked in the screenshot below.

You should see the following page. Now click on the Accept License Agreement radio button as marked in the screenshot below.

Once you accept the license agreement, you should be able to download JDK 10. Now click on the marked download link that ends in .tar.gz in the Linux section.

Your browser should prompt you to save the file. Click on Save File and then click on OK.

Your download should start.

Once the download is complete, you should find the tar.gz archive file in the ~/Downloads/ directory in your user’s HOME directory. At the time of this writing, the name of the archive file is jdk-10.0.1_linux-x64_bin.tar.gz

$ cd ~/Downloads && ls -lh

Installing Oracle JDK 10:

I am going to extract the Oracle JDK 10 .tar.gz archive in /opt directory. You may choose to install it somewhere else. It’s up to you. Just adjust the rest of the article if you do install it somewhere other than /opt.

First extract the Oracle JDK 10 archive file, jdk-10.0.1_linux-x64_bin.tar.gz to /opt directory with the following command:

$ sudo tar xvzf ~/Downloads/jdk-10.0.1_linux-x64_bin.tar.gz -C INSTALL_DIR

Note: In my case, INSTALL_DIR is /opt

The .tar.gz archive should be extracted to /opt directory.

Adding Oracle JDK 10 to the PATH:

Now that Oracle JDK 10 is installed in the /opt directory, a new sub directory should be created in /opt, which you can find out with the following command:

$ ls -lh /opt

As you can see from the marked section of the screenshot below, the directory name is jdk-10.0.1

Note the directory name, because you will need it to set up some environment variables.

Note: The directory name may change as new updates of JDK 10 is released. Adjust it in the rest of the articles, if it changes by the time you read this article.

Now you need to create an environment variable JAVA_HOME with the value /opt/jdk-10.0.1 and add /opt/jdk-10.0.1/bin to the PATH of your Linux Mint 19 operating system. So that you don’t have to type in the full path when you run Java commands.

For example, when you want to compile a Java program, you don’t have to run /opt/jdk-10.0.1/bin/javac, instead you can just run javac if you have the environment variables JAVA_HOME and PATH set up correctly. That’s what I am going to do now.

First create a new file jdk10.sh in /etc/profile.d directory with the following command:

$ sudo nano /etc/profile.d/jdk10.sh

You should see the following window.

Now type in the following lines:

export JAVA_HOME="INSTALL_DIR/JDK_DIR"
export PATH="$PATH:${JAVA_HOME}/bin"

Note: It my case the INSTALL_DIR is /opt and the JDK_DIR is jdk-10.0.1, make sure to replace it correctly.

Finally, it should look something like this.

Now save the file by pressing <Ctrl> + x and then press y and then press <Enter>.

Now reboot your computer with the following command:

$ sudo reboot

Once your computer starts, you can check whether the environment variables JAVA_HOME and PATH is set correctly.

To check whether JAVA_HOME is set, run the following command:

$ echo $JAVA_HOME

As you can see from the marked section of the screenshot below, the JAVA_HOME environment variable has the correct value set.

To check whether the PATH is correctly set, run the following command:

$ echo $PATH | grep jdk

As you can see from the marked section of the screenshot below, the JDK 10’s binary directory is in the PATH.

Testing Oracle JDK 10:

Now you can test whether JDK 10 is working correctly with the following command:

$ javac –version

As you can see from the output of the command, JDK 10.0.1 is working correctly.

Compiling a Simple Java Program with Oracle JDK 10:

In this section I am going to write a simple Java program and compile it using Oracle JDK 10 on Linux Mint 19.

I am going to create a new file Hello.java in the ~/Documents directory in my user’s HOME directory. Hello.java is the Java source code file that I will compile with Oracle JDK 10.

Here are the contents of Hello.java:

public class Hello {

public static void main(String[] args) {

System.out.println("Hello from LinuxHint!");

}

}

Before you can compile the Java program, go to the directory where Hello.java file is saved, which is in my case ~/Documents

$ cd ~/Documents

Now run the following command to compile Hello.java Java source code file with Oracle JDK 10:

$ javac Hello.java

Running a Java Program with Oracle Java 10:

In this section, I will show you how to run the Java program that I compiled in the earlier section of this article.

To run the Hello.java Java source file I just compiled, from the ~/Documents directory where the Hello.java source file is saved and compiled, run the following command:

$ java Hello

Note: When you run the java program, always leave the extension. For example, if the source file is Hello.java, it should be Hello when you want to run it.

As you can see from the marked section of the screenshot below, the correct output is displayed.

That’s how you install and use Oracle JDK 10 on Linux Mint 19. Thanks for reading this article.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *