Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
Do you remember as to how you installed java in the first place? – Raphael Jan 29 at 9:50
    
No, it was so long ago – Sergey Ichtchenko Jan 29 at 10:06
1  
Which java are you asking about? Oracle or Openjdk? – Pilot6 Jan 29 at 13:17
1  
You may want to add the output of "java -version" to your question. – Thorbjørn Ravn Andersen Jan 30 at 1:03
    
Also, the earliest Ubuntu version to have openjdk-8 directly available is 14.10 – Thorbjørn Ravn Andersen Jan 30 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.

share|improve this answer
    
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 Ichtchenko Jan 30 at 8:22
    
@SergeyIchtchenko : See my answer on your question : askubuntu.com/questions/727452/… good luck ! :) – cl-netbox Jan 30 at 11:15

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
share|improve this answer
1  
cl-netbox gave directions to install OpenJDK, not Oracle. OP did not specify whish one he|she asked about. – Pilot6 Jan 29 at 13:17
    
You are right, thank you for the note. I updated. – user284234 Jan 29 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)
JAVA_HOME=/path-to-java-before-bin-directory
export JAVA_HOME

sudo source /etc/environment

and then it was working fine. verify it also:

root@ashu-700-430qe:/DataStax_POC# which java
/usr/bin/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)
root@ashu-700-430qe:/DataStax_POC#

I referred this link. Hope this helps

share|improve this answer

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)

share|improve this answer

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

update-java-alternatives

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.

share|improve this answer
    
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 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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