Install Oracle Java 8 / 9 in Ubuntu 16.04, Linux Mint 18

Oracle Java JDK 9

Quick tutorial for beginners how to easily install Oracle Java JDK8 or JDK9 in Ubuntu 16.04 or Linux Mint 18 via PPA.

Webupd8 Team is maintaining a PPA repository with installer scripts for the latest Java 8 and 9, that automatically downloads the Java archive from Oracle website and sets up everything for you.

1. Add the PPA.

Open terminal (Ctrl+Alt+T) and run the command:

sudo add-apt-repository ppa:webupd8team/java

Type in your password when it asks and hit Enter.


2. Update and install the installer script:

Run commands to update system package index and install Java installer script:

sudo apt update; sudo apt install oracle-java8-installer

You may replace oracle-java8-installer with oracle-java9-installer to install Java 9.

While the install process, you have to accept Java license to continue downloading & installing Java binaries.

Oracle Java License

3. Check the Java version

To check the Java version after installing the package, run command:

javac -version

check out java version

4. Set Java environment variables

The PPA also contains a package to automatically set Java environment variables, just run command:

sudo apt install oracle-java8-set-default

For Java 9, install the package oracle-java9-set-default instead.

About ml

ml is a part time stay-at-home dad who've been using Ubuntu Desktop for a few years. He writes in the free time and wishes to share some useful tips with Ubuntu beginners and lovers.
  • Joe Schmuccatelli

    Well done, it works. Thanks Santa!

  • Sayantan Talukder

    How to set the JAVA_HOME variable?

    • achmiral

      1. Find the java path using this command
      $sudo update-alternatives –config java

      2. Copy the path from your preferred installation and then open /etc/environment using nano or your favorite text editor
      $sudo nano /etc/environment

      3. At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path.
      JAVA_HOME=”put the java path here”

      4. Save and exit the file, and reload it.
      $source /etc/environment

      5. Test
      $echo $JAVA_HOME

      • Parth Vora

        any idea on how to uninstall this?

        • Cyprian Guerra

          I understand this is an old question but /etc/environment is just a file that is sourced (meaning it’s source code is loaded) each time your system boots, so all you need is to remove the line you used to set the JAVA_HOME variable and on your next reboot JAVA_HOME variable won’t be set (or overwritten, whatever you were doing) by /etc/environment. If it is still set, something else is doing this, not your /etc/environment file (check your $HOME files: .profile, .bashrc, .zshrc… I don’t know how java installation loads on your system, some init file might’ve come with a package).

  • iam_ss

    It worked seamlessly!! Great explaination!!

  • Parth Vora

    how do i uninstall this?

  • BeastMan

    One of the easiest, quickest… very impressed

  • Abhinaba Saha

    too good

  • Muaz Niwas

    thanks man!

  • Mohamed Kh Said

    Real helpfull

  • Lipsa Kar

    I am getting this problem on the 2nd step.

    E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    • Niks

      You’re probably running another command that users apt-get…maybe installing some other software in another terminal or updating your system…
      First let that complete and then try the above commands one by one…

  • Venki Ravi

    cool simple solution

  • Ethan

    Nice! This worked for me, thanks!