Installing Java in Ubuntu

This post shows how to install Orcale JDK using apt-get or by downloading from the Oracle site on Ubuntu. It also shows how to install OpenJDK.

Installing Oracle JDK using apt-get

For installing Java in Ubuntu first you need to add Oracle’s PPA (Personal Package Archive) so that Ubuntu knows where to look for updates.

Here note that this repository is not maintained by Oracle. You can refer this URL – But the WebUpd8 Oracle Java PPA doesn’t include any Java binaries, just a script that automatically downloads and install Oracle Java 8.

Then you need to update your package repository. For that use the following command.

After that install Oracle JDK. For that use the following code.

Installing Oracle JDK by downloading manually

If you want to manually download and install Oracle JDK then follow the given steps. You may opt for this way of installing Java in Ubuntu if you are behind a proxy/firewall that is creating problem with connecting to repository.

Go to – and download the required version of Oracle JDK.

Create a directory /usr/java for your Java installation –

installing java

By default gzip file will be downloaded in Downloads directory so copy it from there to the directory /usr/java which you have created.

java installation

Then untar the installation.

java installation

Setting JAVA_HOME environment variable and Java path

In order to find where Java is installed applications refer to JAVA_HOME environment variable. So you need to set up the environment variable and also append the path to Java /bin directory to the PATH. For that you need to edit /etc/environment file.

append path to bin in existing PATH- :/usr/java/jdk1.8.0_151/bin

Add JAVA_HOME environment variable at the end of the file.


Make sure to use installation path as per your Java installation.

After that reload the variables by running this command

You can verify that the environment variable is set correctly or not by running the following command-

Also check the Java installation by running the following command –

You should get the output for the version you have installed which should look something like this.

Installing OpenJDK

If you want to install OpenJDK

If you want to install just the Java Runtime Environment

Want to write your first Java program after installing Java, have a look at this post- Writing First Java Program – Hello World

That’s all for the topic Installing Java in Ubuntu. If something is missing or you have something to share about the topic please write a comment.

You may also like


  1. Pingback: Installing Hadoop in Pseudo-distributed mode – Technical Tutorials

  2. Pingback: final in Java - KnpCode

  3. Pingback: How to Dual-Boot Ubuntu And Windows - KnpCode

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.