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.

java-installer-ppa

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.

23 comments

  1. Well done, it works. Thanks Santa!

  2. How to set the JAVA_HOME variable?

    • 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

      • any idea on how to uninstall this?

        • 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).

  3. It worked seamlessly!! Great explaination!!

  4. how do i uninstall this?

  5. One of the easiest, quickest… very impressed

  6. too good

  7. thanks man!

  8. Real helpfull

  9. 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?

    • 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…

    • This will happen during the first minute or so after logging in on Ubuntu if you have enabled automatic updates. A background task is running which in essence is doing “apt update” followed by “apt upgrade”. Until that completes the dpkg lock is engaged. Once that completes you won’t get the error.

  10. cool simple solution

  11. Nice! This worked for me, thanks!

  12. Short, sweet, and to the point.

  13. Balamurugan Vellaichamy

    Thank you, it helped me when i struck

  14. Rubanraj Ravichandran

    short and simple.. thanks