Moving from JDK 1.7 to JDK 1.8 on Ubuntu

129,812

Solution 1

This is what I do on debian - I suspect it should work on ubuntu (amend the version as required + adapt the folder where you want to copy the JDK files as you wish, I'm using /opt/jdk):

wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u71-b15/jdk-8u71-linux-x64.tar.gz
sudo mkdir /opt/jdk
sudo tar -zxf jdk-8u71-linux-x64.tar.gz -C /opt/jdk/
rm jdk-8u71-linux-x64.tar.gz

Then update-alternatives:

sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_71/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_71/bin/javac 1

Select the number corresponding to the /opt/jdk/jdk1.8.0_71/bin/java when running the following commands:

sudo update-alternatives --config java
sudo update-alternatives --config javac

Finally, verify that the correct version is selected:

java -version
javac -version

Solution 2

Just use these command lines:

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

If needed, you can also follow this Ubuntu tutorial.

Solution 3

Add the repository and update apt-get:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Install Java8 and set it as default:

sudo apt-get install oracle-java8-set-default

Check version:

java -version

Solution 4

You can easily install 1.8 via PPA. Which can be done by:

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

Then check the running version:

$ java -version

If you must do it manually there's already an answer for that on AskUbuntu here.

Solution 5

You can do the following to install java 8 on your machine. First get the link of tar that you want to install. You can do this by:

  1. go to java downloads page and find the appropriate download.
  2. Accept the license agreement and download it.
  3. In the download page in your browser right click and copy link address.

Then in your terminal:

$ cd /tmp
$ wget http://download.oracle.com/otn-pub/java/jdk/8u74-b02/jdk-8u74-linux-x64.tar.gz\?AuthParam\=1458001079_a6c78c74b34d63befd53037da604746c
$ tar xzf jdk-8u74-linux-x64.tar.gz?AuthParam=1458001079_a6c78c74b34d63befd53037da604746c
$ sudo mv jdk1.8.0_74 /opt
$ cd /opt/jdk1.8.0_74/
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_91/bin/java 2
$ sudo update-alternatives --config java // select version
$ sudo update-alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_91/bin/jar 2
$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_91/bin/javac 2
$ sudo update-alternatives --set jar /opt/jdk1.8.0_91/bin/jar
$ sudo update-alternatives --set javac /opt/jdk1.8.0_74/bin/javac
$ java -version // you should have the updated java
Share:
129,812
Johan
Author by

Johan

Updated on July 05, 2022

Comments

  • Johan
    Johan almost 2 years

    I am on UBUNTU. JDK version currently installed is:

    java version "1.7.0_51"
    Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
    

    the configuration being installed is:

    sudo update-alternatives --config java
    There is only one alternative in link group java 
    (providing /usr/bin/java):     /usr/lib/jvm/java-7-oracle/jre/bin/java
    

    I downloaded the latest tar.gz archive of JDK 1.8.

    How can I easily install JDK 1.8 from tar.gz overriding/uninstalling the JDK 1.7 currently installed? Or even without explicitly use the tar.gz.

  • SupaJord
    SupaJord about 9 years
    Can you tell me specifically which command failed? The first one?
  • Johan
    Johan about 9 years
    The second one... lots of messages like these: W: Failed to fetch it.archive.ubuntu.com/ubuntu/dists/saucy-backports/restricte‌​d/… 404 Not Found [IP:...
  • SupaJord
    SupaJord about 9 years
    Are you using an LTS release of Ubuntu?
  • Johan
    Johan about 9 years
    lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 13.10 Release: 13.10 Codename: saucy
  • Johan
    Johan about 9 years
    you think I should upgrade this Ubuntu to 14.04 LTS?
  • SupaJord
    SupaJord about 9 years
    Ubuntu 13.10 is end-of-live and has been since July of 2014. Maybe they left the packages on the server for a while, but they are gone now. The best thing to do is installing a supported release of Ubuntu. Or if you don't want to upgrade you'll need to attempt a manual installation like I liked in the original answer.
  • Johan
    Johan about 9 years
    I solved with this: askubuntu.com/questions/56104/…
  • Qtax
    Qtax over 8 years
    Newer jdk, 8u60, found at: http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u6‌​0-linux-x64.tar.gz Note that this will not work without the cookie set, so use wget as in the answer.
  • matanster
    matanster over 8 years
    Thanks. In my case it was already installed but just not the default. sudo update-alternatives --config javac was then enough.
  • thatWiseGuy
    thatWiseGuy over 8 years
    Worked for me using jdk 8u65. Thanks!
  • fracz
    fracz over 8 years
    This does not differ from the answer above in any way.
  • SupaJord
    SupaJord about 8 years
    Idk if you've noticed but I was the first to answer -_-' well besides Kapcash below who beat me by two minutes.
  • Eliran Malka
    Eliran Malka about 8 years
    easiest one so far, thanx!
  • Adam Tuttle
    Adam Tuttle about 8 years
    The java 8 installer seems to require interaction to agree to their TOS, even with apt-get install -y... Is there any way to force it to agree from the command line so that this can be automated, e.g. in Vagrant?
  • deanresin
    deanresin almost 8 years
    How do you remove the older versions safely after install the newer version?
  • Tilak Madichetti
    Tilak Madichetti over 7 years
    Java 9 is gonna release shortly . just for extra information though : )
  • ChuckCottrill
    ChuckCottrill about 7 years
    When your system is behind a proxy, use 'sudo -E' to preserve environment, and make sure appropriate proxy env's are configured.
  • Sonal Dalal
    Sonal Dalal over 6 years
    Installed successfully.
  • John Strood
    John Strood over 6 years
    Update: the url gives a 404. Still, one could just download tar file and follow the rest of the instructions.
  • Hikaru Shindo
    Hikaru Shindo over 2 years
    Package 'oracle-java8-installer' has no installation candidate