I would like to update my java version (UPDATE, not install) on my ubuntu 12.04 computer. I currently have java 7.x, and I would like to update it to the newest version possible (8.0 at least) without it being too complicated.

  • Do you remember as to how you installed java in the first place?
    – Raphael
    Jan 29 '16 at 9:50
  • No, it was so long ago
    – Sergey
    Jan 29 '16 at 10:06
  • 1
    Which java are you asking about? Oracle or Openjdk?
    – Pilot6
    Jan 29 '16 at 13:17
  • 1
    You may want to add the output of "java -version" to your question. Jan 30 '16 at 1:03
  • Also, the earliest Ubuntu version to have openjdk-8 directly available is 14.10 Jan 30 '16 at 1:04

Java 8 is not available in the Ubuntu 12.04 repositories, but it is available from a Launchpad PPA.

You also cannot update a Java version to the next Java version, but you can install different Java versions side by side.

To install Java version 8 (OpenJDK 8 edition - not ORACLE Java 8) open a terminal and execute :

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk  

If you only want to install the Java Runtime Environment :

sudo apt-get install openjdk-8-jre  

Note 1 :

As you said "... without it being too complicated ...", I assumed that you installed Java 7 from the Ubuntu repositories, which contain OpenJDK and did not add the WebUpd8 PPA (ORACLE Java).

Note 2 :

As you said that you get the File "/usr/bin/add-apt-repository", line 37 print _("The %s named '%s' has no PPA named '%s'" ^ SyntaxError: invalid syntax error, have a look here.

Suggestion :

Keep both versions installed side by side, some other packages or programs might rely on Java 7.

However, when you don't want to have both versions and if don't need Java 7 anymore ... remove it.

  • It says that I cannot add the PPA: File "/usr/bin/add-apt-repository", line 37 print _("The %s named '%s' has no PPA named '%s'" ^ SyntaxError: invalid syntax
    – Sergey
    Jan 30 '16 at 8:22

As you did not specify whether you want to install OpenJDK or Oracle JDK, my answer covers Oracle JDK.

It is interesting to quote this text from here. What follows applies to JDK8 too and for all Ubuntu versions of yours or higher.

Oracle JDK7 itself is not hosted in the PPA because that's not allowed by the new Java license (which is also the reason why it has been removed from the official Ubuntu repositories); the package in the PPA automatically downloads Oracle Java JDK 7 from its official website and installs it on your Ubuntu / Linux Mint computer, just like the flashplugin-installer package does.

Note that JDK9 is expected to be released during this year, so do not try to use before that.

For this reason, this is is how to install (and not update) your Java 8 version:

sudo add-apt-repository ppa:webupd8team/java 
sudo apt-get update
sudo apt-get install oracle-java8-installer
  • 1
    cl-netbox gave directions to install OpenJDK, not Oracle. OP did not specify whish one he|she asked about.
    – Pilot6
    Jan 29 '16 at 13:17
  • You are right, thank you for the note. I updated.
    – user284234
    Jan 29 '16 at 15:51

Adding to the earlier answers...I had issues with my JAVA_HOME after the install from this ppa following this commands:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

The 4th command doesn't work as expected. So in my case I have to manually run these commands:

sudo /etc/environment(add the below two lines and append to PATH if needed)
export JAVA_HOME

sudo source /etc/environment

and then it was working fine. verify it also:

root@ashu-700-430qe:/DataStax_POC# which java
root@ashu-700-430qe:/DataStax_POC# java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

I referred this link. Hope this helps


An alternative is the Zulu port of OpenJDK which can be downloaded as a zip file, unpacked and used directly.

If needing to run from the command line, consider prepending the bin directory to $PATH in .bash_profile.

Downloads available at http://www.azul.com/downloads/zulu/zulu-linux/

(untested as I do not have a 12.04 system available. It appears though that the requirement of glibc being at least 2.5 is satisfied)


If you want keep both versions, and switch depending on your needs, consider the command:


to make sure that a particular java (sun-java) is the default runtime. Use update-java-alternatives --list to display all possible options, and update-java-alternatives --set <java version name from --list> to switch it.

  • Java is tricky to configure using the alternatives, since it has many components. This is why there is the update-java-alternatives command. You should update your answer to reflect this.
    – philsf
    Jan 29 '16 at 16:28

Another possible solution is to add the PPA repository from the project ubuntu-justchedavailable in the Github. This will provide a little bit different solution because it will download the Oracle JRE tarball to a previously configured directory and generate a DEB package from it.

That way you won't depend on somebody else packing the JRE, you will do it yourself (don't worry, it will be a automatic process).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.