Install jdk 8 on Ubuntu

java logo

Ubuntu versions:

  • Ubuntu GNU/Linux 14.04 (Trusty Tahr)
  • Ubuntu GNU/Linux 13.10 (Saucy Salamander)
  • Ubuntu GNU/Linux 13.04 (Raring Ringtail)

Installing Oracle JDK 8 on Ubuntu:

  • Download the Oracle JDK 8 tar file from here
  • Extract the tar file: 
tar -xvzf jdk-8-linux-x64.tar.gz
  • Create jvm folder in /usr/lib, if jvm folder not exist
sudo mkdir /usr/lib/jvm
  • Move extracted jdk 8 folder to this location:
sudo mv jdk1.8.0 /usr/lib/jvm/jdk1.8.0
  • Install new java source in system:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1
# Java Web Start (javaws) is no longer required to be installed!
# sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8.0/bin/javaws 1
  • Choose default java:
sudo update-alternatives --config javac
sudo update-alternatives --config java
# Java Web Start (javaws) is no longer required to be installed!
# sudo update-alternatives --config javaws
  • Java version test:
java -version

# java version "1.8.0"
# Java(TM) SE Runtime Environment (build 1.8.0-b132)
# Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
  • Verify the symlinks all point to the new java location:
ls -la /etc/alternatives/java*
  • Enable Java plugin for Mozilla Firefox (even for Chrome)
# for 64-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/ /usr/lib/mozilla/plugins
# for 32-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/ /usr/lib/mozilla/plugins
  • JAVA_HOME configuration: Some tools require JAVA_HOME variable. You can set JAVA_HOME on Ubuntu either:
    1. With /etc/environment:
    2. sudo gedit /etc/environment
      # add the following line, save and exit
    3. Or in your home directory with .bashrc:
    4. sudo gedit .bashrc
      # add the following lines, save and exit
      export JAVA_HOME=/usr/lib/jvm/jdk1.8.0
      export PATH=$JAVA_HOME/bin:$PATH


  1. Giampaolo
    May 18, 2014 @ 10:37:28

    Simple and straightforward. Thanks.


    • Anonymous
      Dec 06, 2016 @ 18:02:08

      Thanks a lot… :)
      I think this a good contribution from your side sir.


  2. Alex
    Jul 02, 2014 @ 15:29:18

    PPAs damn!!!! Thank you.


  3. Sajid
    Aug 08, 2014 @ 21:58:19

    Fantastic!! you have saved me a significant of time


  4. Duncan Calvert
    Oct 13, 2014 @ 19:04:52

    Epic post. Thanks!


  5. Devilal
    Dec 17, 2014 @ 14:17:32

    Article is very helpful. Thank you.


  6. Martin
    Dec 30, 2014 @ 04:17:13

    It works. Thanks.

    I went further and found the full list of alternatives installed by openjdk 7 through:

    sudo update-alternatives –get-selections | grep java

    This is the resulting list:

    appletviewer auto /usr/lib/jvm/java-7-openjdk-amd64/bin/appletviewer
    extcheck auto /usr/lib/jvm/java-7-openjdk-amd64/bin/extcheck
    idlj auto /usr/lib/jvm/java-7-openjdk-amd64/bin/idlj
    jar auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jar
    jarsigner auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jarsigner
    java auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
    javac auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
    javadoc auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
    javah auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javah
    javap auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javap
    jcmd auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jcmd
    jconsole auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jconsole
    jdb auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jdb
    jexec auto /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jexec
    jhat auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jhat
    jinfo auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jinfo
    jmap auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jmap
    jps auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jps
    jrunscript auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jrunscript
    jsadebugd auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jsadebugd
    jstack auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jstack
    jstat auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jstat
    jstatd auto /usr/lib/jvm/java-7-openjdk-amd64/bin/jstatd
    keytool auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/keytool
    native2ascii auto /usr/lib/jvm/java-7-openjdk-amd64/bin/native2ascii
    orbd auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/orbd
    pack200 auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/pack200
    policytool auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/policytool
    rmic auto /usr/lib/jvm/java-7-openjdk-amd64/bin/rmic
    rmid auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/rmid
    rmiregistry auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/rmiregistry
    schemagen auto /usr/lib/jvm/java-7-openjdk-amd64/bin/schemagen
    serialver auto /usr/lib/jvm/java-7-openjdk-amd64/bin/serialver
    servertool auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/servertool
    tnameserv auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/tnameserv
    unpack200 auto /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/unpack200
    wsgen auto /usr/lib/jvm/java-7-openjdk-amd64/bin/wsgen
    wsimport auto /usr/lib/jvm/java-7-openjdk-amd64/bin/wsimport
    xjc auto /usr/lib/jvm/java-7-openjdk-amd64/bin/xjc

    Just in case someone is interested.


  7. izar
    Jan 12, 2015 @ 01:44:21

    it works ! u r the hero today…


  8. narayan
    Apr 12, 2015 @ 08:22:23

    when i executive same command on 32 bit ubuntu 13.04 to install latest jdk8 tar.gz downloaded from oracle , it say ” cannot execute binary file” I m in need of help


    • Cem Ikta
      Apr 13, 2015 @ 11:34:18

      Maybe your JDK download was not successful!


  9. Sutej
    Jun 10, 2015 @ 08:27:33

    Thank you so much admin! i am trying since 4 days. and you have solved it in few minutes. thank u


  10. Bifrous
    Jul 13, 2015 @ 18:05:30

    Many Thanks!


  11. ilaiyaraja
    Nov 14, 2015 @ 11:43:36

    Nice article. It helps.


  12. Namnodorel
    Dec 24, 2015 @ 12:54:19

    Worked! Thank you very much!


  13. fasdgoc
    May 27, 2016 @ 22:15:42

    Thank you ~!


  14. Install JDK 8 on Ubuntu | Cem's Blog
    Dec 25, 2016 @ 21:27:50

    [...] post is from my old blog! in Featured / Java 0 comments SharePost [...]


  15. asmaâ
    Feb 14, 2017 @ 01:49:15

    thanks, but i have a problem with the upedate of alternatives, any solution?


  16. rodrigue aime
    May 18, 2018 @ 17:38:19

    thank for this post. When i execute the following command for JDK8 32bits i have:
    rodrigue@ubuntu:/usr/lib/jvm$ sudo update-alternatives –install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8.0_172/bin/javaws 1
    update-alternatives: erreur: le chemin alternatif /usr/lib/jvm/jdk1.8.0_172/bin/javaws n’existe pas

    javaws is not present in the bin folder. please one solution is need.


    • Cem Ikta
      May 22, 2018 @ 11:35:46

      Currently Java Web Start (javaws) is no longer required to be installed! I have edited the post. Thanks for feedback.


Leave a Reply