How to Install Java on Ubuntu 16.04

How to Install Java on Ubuntu 16.04

install java ubuntuWe’ll show you 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, if you follow this step by step guide below, carefully!

1. Log in to your VPS via SSH

First, log in to your VPS via SSH using:

ssh my_sudo_user@my_server

Install Java on Ubuntu 16.042. Update the OS packages

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.

3. Install Java JDK via PPA on Ubuntu 16.04

We will use the PPA repository maintained by the Webupd8 Team for installing Java on Ubuntu 16.04. 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

4. Install JDk8 on Ubuntu 16.04

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)

5. Install JDK7 on Ubuntu 16.04

If you need to install JDK7 run:

sudo apt install oracle-java7-installer

6. JDK9 developer preview version on Ubuntu 16.04

To install the JDK9 developer preview version run:

sudo apt install oracle-java9-installer

7. Manually install Oracle Java JDK on Ubuntu 16.04

Download the latest JDK8 from the Oracle website with wget:

cd /tmp
wget --continue --no-check-certificate --header "Cookie: oraclelicense=a" 'http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz'

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/jdk.sh with the following content:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
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/jdk.sh

Finally, the same as before, to check if everything is set up 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)

SEE ALSO: How to Install Java 10 on Debian 9


Installing Java on Ubuntu 16.04

That’s it. You have successfully installed Java on Ubuntu 16.04. After going through this guide, you should be familiar with how to install 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 16.04 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. Here’s our latest update on How to Install Java on Ubuntu 20.04.

PS. If you liked this tutorial, on how to Install Java on Ubuntu 16.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

5 thoughts on “How to Install Java on Ubuntu 16.04”

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

    Thanks

    Reply
    • Hello,

      /etc/profile.d/jdk.sh 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.

      Thanks.

      Reply

Leave a Comment