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
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
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/libnpjp2.so /usr/lib/mozilla/plugins
# for 32-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so /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
      JAVA_HOME=/usr/lib/jvm/jdk1.8.0
    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