How to Install Java on Ubuntu 16.04

How to Install Java on Ubuntu 16.04

How to install Java on Ubuntu 16.04. Oracle JDK is the official version distributed by Oracle. These guide should also work on Debian and Linux Mint, but was tested and written for Ubuntu. Installing Java on Ubuntu 16.04 is an easy task, just follow this step by step guide below.

1. Log in to your VPS via SSH and update your system

First, log in to your VPS via SSH using:

ssh [email protected]_server

Make sure your OS package list and the OS packages are up to date by running the following commands:

sudo apt-get update && sudo apt-get -y upgrade

There are different ways to install JAVA, like using a Personal Package Archive (PPA) software repository, or by downloading the Java source packages on your server and install them manually, etc.

2. Install Oracle Java JDK via PPA

Install Java on Ubuntu

We will use the PPA repository maintained by the Webupd8 Team. The install script will ask you to accept the license agreement and it will download the Java archive file from the Oracle download page and set up everything for you.

To add the Webupd8 Team PPA repository, run the following commands on your server:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update

You can now install JDK8 with the following command:

sudo apt install oracle-java8-installer

To check if everything is set correctly run:

java -version

and you should see something like the following:

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

If you need to install JDK7 run:

sudo apt install oracle-java7-installer

To install the JDK9 developer preview version run:

sudo apt install oracle-java9-installer

3. Manually install Oracle Java JDK

Download the latest JDK8 from the Oracle website with wget:

cd /tmp
wget --continue --no-check-certificate --header "Cookie: oraclelicense=a" ''

Extract the archive with the following command:

tar -xf jdk-8u121-linux-x64.tar.gz

Move the directory:

sudo mkdir -p /usr/lib/jvm
sudo mv jdk1.8* /usr/lib/jvm/java-8-oracle

and set the default Java version:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-oracle/jre/bin/java 1091
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-8-oracle/bin/javac 1091

To set JAVA environment variables, create a new file /etc/profile.d/ with the following content:

export J2SDKDIR=/usr/lib/jvm/java-8-oracle
export J2REDIR=/usr/lib/jvm/java-8-oracle/jre
export PATH=$PATH:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export DERBY_HOME=/usr/lib/jvm/java-8-oracle/db

and run the following command:

sudo source /etc/profile.d/

Finally, same as before, to check if everything is setup correctly, run:

java -version

and you should see something like the following:

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

how to install java on ubuntu 16.04

That’s it. You have successfully installed Java on Ubuntu 16.04. You can now install JAVA based software such as Tomcat, GitBucket, GlassFish 4 and many more. If you have any questions or encounter any problem with the installation of Java SDK on your Ubuntu server, please post a comment below.

Of course, you don’t have to Install Java on Ubuntu 16.04, if you use one of our JAVA VPS Hosting services, in which case you can simply ask our expert Linux admins to Install Java on Ubuntu 16.04, for you. They are available 24×7 and will take care of your request about installing Java on Ubuntu 16.04, immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

How to Install Jupyter on an Ubuntu 16.04
How to install Symfony 3 Framework with Nginx on Ubuntu 14.04
How to install PrestaShop on an Ubuntu 14.04 VPS
  • Reza Takhshid

    thank you, it worked great.
    Btu I would appreciate it if you would explain exactly what does the does? and the source command.


    • admin


      Author Reply


      /etc/profile.d/ is used to set up the the Java environment variables. For more information about what content you should add in the file please check the blog post.


  • comy


    Author Reply

    sudo: source: command not found

    • admin


      Author Reply

      You can run the command without `sudo`.

Free Migration to RoseHosting. Award Winning Linux VPS Hosting with Fully Managed Support. Coupon RHBLOG50 for 50% offOrder Now