Install Oracle Java JRE/JDK on Ubuntu 18.04 LTS

If you’re going to be developing any kind of Java programs on Ubuntu, then you’re definitely going to need Java Runtime environment… the steps below show you how to get Oracle Java JRE  / JDK installed…

Oracle Java JDK is a development environment for developing applications and tools based on Java. It can also be used for testing applications and program developed using the Java programming language.

This brief tutorial is going to show students and new users how to download Oracle Java JDK / JRE and install on Ubuntu 18.04 LTS. Other tutorials may show you how to get Java installed via third-party PPA tools.

You could also install OpenJava JDK / JRE easily using the apt-get command. However, this post is going show you how to download and install Java from its original repository instead of the opensource version of via third-party.

To get Java JDK / JRE installed, follow the steps below:

Step 1: Download Java JDK

Java JDK can be downloaded from the link below directly from Oracle’s website. Choose the .tar.gz pacakge for Linux x86 or x64 and download.

Take notes of the version you’re downloading… If there’s a newer version then the one below, then download it and replace the version number in the commands below…

After downloading go and extract the downloaded package.

Step 2: Extract and Install Java

Now that you’ve downloaded the correct archive package for your system, run the commands below to extract it.

tar -xvf ~/Downloads/jdk-*.tar.gz

Next, create a directory to store the Java compiler packages. you can name it what ever you want, but it nice to name it after the Java version you’re installing.

sudo mkdir -p /usr/lib/jvm/jdk-9.0.4/

Next, run the commands below to copy the extract Java content into the newly created directory.

sudo mv jdk-9.0.4*/* /usr/lib/jvm/jdk-9.0.4/

Then run the commands below to configure Java

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-9.0.4/bin/java" 1010 
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-9.0.4/bin/javac" 1010 
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk-9.0.4/bin/javaws" 1010

Step 3: Create Java Environment Variables

To set JAVA environment variables, open the /etc/profile file by running the commands below…

sudo nano /etc/profile.d/

Then copy and paste the lines into the end of the file and save…

export J2SDKDIR=/usr/lib/jvm/jdk-9.0.4
export J2REDIR=/usr/lib/jvm/jdk-9.0.4/jre
export PATH=$PATH:/usr/lib/jvm/jdk-9.0.4/bin:/usr/lib/jvm/jdk-9.0.4/db/bin:/usr/lib/jvm/jdk-9.0.4/jre/bin
export JAVA_HOME=/usr/lib/jvm/jdk-9.0.4
export DERBY_HOME=/usr/lib/jvm/jdk-9.0.4/db

Next, run the commands below

source /etc/profile.d/

The commands above should configure Java to work and function with Ubuntu. To test if Java is installed correctly, run the commands below.

java –version

You should see Java as been installed.

java 9.0.4
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

Congratulations! You’ve just successfully install Java JDK


This brief tutorial shows students and new users how to easily install Java JDK on Ubuntu 18.04 LTS. It is an alternate method that are available across the internet that show users how to install Java from third-party PPAs or the OpenJDK versions.

This method installs the original versions from Oracle.


You may also like the post below:


  1. Thank you :)

  2. Looking forward to using this tool

  3. sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk-9.0.4/bin/java” 1010 is getting error

    1. Got solution?

  4. “This brief tutorial shows students and new users how to easily install Java JDK on Ubuntu 18.04 LTS.”
    This was a bit cumbersome compared to a Java install in Windows..

  5. Very useful. Thank You.

  6. Thank You! It worked without any issues for version 10.0.2 as well

  7. Works perfectly with 10.0.2


    After a long journey looking updated codes, this worked for me thanks very much

  9. Excellent tutorial. I followed all the steps with successful.

  10. Ao inves de usar links normais para indicar sites use links que abram em outra guia….ajudaria muito…
    Acrescente -> “

  11. In the section for configuring java, there are 3 separate instructions. For e.g.

    sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk-9.0.4/bin/java” 1010

    What does 1010 mean? What does it do?

  12. “Then copy and paste the lines into the end of the file and save…”

    Please explain how to “save…”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.