Install Java JDK/JRE On Ubuntu 16.04/17.04 [100% Working]

February 02, 2018 | | TAG: ubuntu | No comments:
install java in ubuntu 16.04
install java in ubuntu

Java and JVM(Java Virtual Machine) are widely used and required for many kinds of software. You can install Oracle Java JDK/JRE in Ubuntu 17.04 or 16.04 using apt-get command and by downloading packages.

In some Colleges and Universities, Students must install Java to compile and run java programs. While making Android applications using Android Studio, Java JDK must be needed.

Some universities use .jar files to conduct Exams for students, Java JRE(Java Runtime Environment) helps you open that .jar files.

First of all, you need to check whether Java is installed on your Linux system. For that, open Ubuntu Terminal(Ctrl+Alt+T). Type java --version and press Enter. If you get the message like in the below box then Java is not installed on your system.

   vineel@jucotech:~$ java --version
   The program 'java' can be found in the following packages:
   * default-jre
   * openjdk-8-jre-headless
   * gcj-4.8-jre-headless
   * gcj-4.9-jre-headless
   * gcj-5-jre-headless
   * gcj-6-jre-headless
   * openjdk-9-jre-headless
   Try: sudo apt install 

#1. Installing The Default Java JDK/JRE Using Apt-Get

This is the easiest method for installing Java. Basically, this method installs Open JDK 8/9, the latest and recommended version.

First, Update the package.

  sudo apt-get update

Next, install Java. Specifically, this method will install JRE.

  sudo apt-get install default-jre

JDK(Java Development Kit) is only needed if you want to run java programs or specifically if the software that uses java require it. Generally, JRE comes with JDK itself. If you install JDK then you don't need to install JRE again.

Install JDK with this command.

  sudo apt-get install default-jdk

#2. Installing Oracle JDK

If you want to install Oracle JDK officially distributed by Oracle, then follow the below steps.

First, add Oracle's PPA and then update your package respiratory.

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

To install JDK 8, use the following command:

sudo apt-get install oracle-java8-installer

To install JDK 9, use the following command:

sudo apt-get install oracle-java9-installer

After installing JDK 8 or 9, Manage Java using update-alternatives command

sudo update-alternatives --config java

After running the update-alternatives command the output will look like this for all Java versions.

There are 5 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-6-oracle/jre/bin/java          1         manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          2         manual mode
  3            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  4            /usr/lib/jvm/java-8-oracle/jre/bin/java          3         manual mode
  5            /usr/lib/jvm/java-9-oracle/bin/java              4         manual mode

Press  to keep the current choice[*], or type selection number:

Now choose the number to use it as a default. You can also update-alternatives for other java commands like compiler(javac), the documentation generator(javadoc), the JAR signing tool (jarsigner), and more.

sudo update-alternatives --config command
In the place of command type the required command like javac or javadoc or jarsigner.

#3. Installing Oracle JDK By Downloading tar.gz File.

First of all, check your system version whether it is 32-bit or 64 bit. Now, download the Java JDK .tar.gz file(x64 or x86) directly from the Oracle's Website.

If there is bold(javafile) font then replace it with your java file name.

Now run the below command to extract your downloaded java file.

tar -xvf ~/Downloads/javafile.tar.gz

Next, create a directory to store the Java compiler packages.

sudo mkdir -p /usr/lib/jvm/javafile/

Next, run the commands below to copy the extract Java content into the newly created directory.

sudo mv jdk1.8*/* /usr/lib/jvm/javafile/

Then run the commands below to configure Java

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/javafile/bin/java" 1 
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/javafile/bin/javac" 1 
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/javafile/bin/javaws" 1

The commands above should configure Java to work and function with Ubuntu.

Below one is an optional process, but it would be better if you do consider the below process.

Setting the JAVA_HOME Environment Variable

Many software uses JAVA_HOME variables to detect the java installation location. To set this environment variable, first, find out where Java is installed. For that run the below command.

sudo update-alternatives --config java

Now, Copy the path from your preferred installation and then open /etc/environment using nano.

sudo nano /etc/environment

At the end of this file, add the following line, making sure to replace the bold path with your own copied path.


Save and exit the file, and reload it.

source /etc/environment

You can now test whether the environment variable has been set by executing the following command:


This will return the path you just set.

Final Words

After the completion of the above process. Open your Ubuntu terminal(Ctrl+Alt+T) and type java --version.

If you get the below message then you have successfully installed Java in your Ubuntu system.

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Post a Comment

Don't Miss An Update