Skip to content

How to install Java Ubuntu

Rate this post

How to install Java Ubuntu: Are you taking your first steps into the world of Ubuntu and need a hand to install Java on your computer? No problem, you’ve come to the right place at the right time. You just have to tell me which version of the software you need, there is more than one: there is the classic Java from Oracle (the one also available for Windows and OS X) and then there is OpenJDK, an open source implementation of Java Standard Edition created with the contributions of Oracle and the open Java community.

Technically they don’t differ much. Oracle Java includes some closed source components that are not present in OpenJDK (which is completely open source), but from the user’s point of view – to run Java applications and games – both should be fine. That being said, some software and video games work best with Oracle’s Java, so I’d tend to recommend that.

So, are you ready to go to work? If you want to find out how to install Java Ubuntu, all you have to do is take five minutes of free time and follow the instructions below. The tutorial is suitable for all the most recent versions of the famous Linux distro released by Canonical. Happy reading and enjoy!

Install Oracle Java on Ubuntu

Before installing any version of Java on your computer, check if any version of the software is already present in Ubuntu. To do this, open the Terminal (if you don’t know how to get there, click on the Ubuntu logo in the left sidebar and look for the Terminal from the menu that opens) and type the following command.

java -version

If any version of Java is already present on the PC, you will see its name in the Ubuntu Terminal (eg openjdk version “1.8.0_xx-internal” ), otherwise the writing will appear. The “java” program can be found in the following packages (… ) with the list of Java packages available for download.

If you have OpenJDK and want to replace it with Oracle’s Java, uninstall the open version of the software by typing the following command in the Terminal . After pressing the Enter key on the PC keyboard you will have to type the password of your user account on Ubuntu (the one you use to access the system).

sudo apt-get purge openjdk*

At this point you must communicate to Ubuntu the repository from which to draw the version of Java distributed by Oracle. Then go back to the Terminal and give the following commands (the first is for adding Java to the repositories, the second updates the list of all the repositories configured in Ubuntu).

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

Now you have to choose which version of Java to install: the number 8 or the number 7. To tell the truth, Java 9 is also available, but currently it is not yet stable and therefore its use is not recommended.

If you want, you can also keep multiple versions of Java installed on the same computer and set the one you prefer as the default (we’ll see how to do it shortly).

Oracle Java 8 for Ubuntu

How to install Java Ubuntu

To install Java 8 on Ubuntu, open the Terminal and issue the following command.

sudo apt-get install oracle-java8-installer

When the message After this operation appears on the screen , xx kB of disk space will be occupied. To continue? [Y / n] , type Y in the Terminal and press the Enter key on the computer keyboard. Then accept the conditions of use of the program, pressing first on the OK button and then on Yes , and wait for the installation of Java 8 to be completed. It shouldn’t be long.

At the end of the procedure, to verify that everything went in the right direction, go back to the Ubuntu Terminal and give the java -version command . The java version “1.8.8_xx” should appear .

To automatically set the environment variables JAVA_HOME and PATH , also install the following package.

sudo apt-get install oracle-java8-set-default

Oracle Java 7 for Ubuntu

How to install Java Ubuntu

If you want to install Java 7 , the procedure to follow is practically the same as we saw previously for Java 8. Open the Terminal and give the command.

sudo apt-get install oracle-java7-installer

At the end of the operation, to verify that everything went in the right direction, go back to the Terminal and give the command java -version . The java version “1.7_xx” should appear .

To automatically set the environment variables JAVA_HOME and PATH , also install the following package.

sudo apt-get install oracle-java7-set-default

How to manage Java installations

How to install Java Ubuntu

If you have installed multiple versions of Java on the same computer and want to set one of them as the default interpreter (so that applications and games use it by default), open the Terminal and give the following command.

sudo update-alternatives --config java

A list will appear with all the versions of Java installed on your computer and, next to each of them, the numbers to be typed to set them as the default Java interpreter.

Then type the number corresponding to the version of Java you want to set as default (e.g. 1 or 2 ), press the Enter key on your PC keyboard and you’re done. If you want to set a version of Java as the default compiler, use the command below.

sudo update-alternatives --config javac

If instead you want to uninstall one version of Java from the PC to keep only the other, open the Terminal and give the following command.

sudo apt-get purge oracle-java7-installer (to uninstall Java 7)

sudo apt-get purge oracle-java8-installer (to uninstall Java 8)

When After this operation appears on the screen , xx kB of disk space will be freed. To continue? [Y / n]? , type S in the Terminal and press the Enter key to complete the operation.

Install OpenJDK on Ubuntu

How to install Java Ubuntu

We continue this guide on how to install Java Ubuntu by taking care of OpenJDK , the open source implementation of Java Standard Edition created by the open Java community and Oracle. To install OpenJDK on Ubuntu 14.10 and later, open the Terminal and give one of the following commands (install only the Java versions you need).

sudo apt-get install openjdk-8-jre (to install version 8 of OpenJDK)

sudo apt-get install openjdk-7-jre (to install version 7 of OpenJDK)

sudo apt-get install openjdk-8-jdk (to install version 8 of OpenJDK including development tools)

sudo apt-get install openjdk-7-jdk (to install version 7 of OpenJDK including development tools)

You will be asked to enter your user account password on Ubuntu. When After this appears on the screen , xx MB of disk space will be occupied. To continue? [S / n] , type S in the Ubuntu Terminal and press the Enter key on your PC keyboard to complete the operation.

Do you use Ubuntu 14.04 or 12.04 ? No problem, you can install OpenJDK by adding a repository to your operating system and giving a handful of Terminal commands.

sudo add-apt-repository ppa:openjdk-r/ppa (to add the OpenJDK repository to Ubuntu)

sudo apt-get update (to update the list of repositories)

sudo apt-get install openjdk-8-jdk (to install version 8 of OpenJDK including development tool)

sudo apt-get install openjdk-8-jre (to install version 8 of OpenJDK)

sudo apt-get install openjdk-7-jdk (to install version 7 of OpenJDK including development tool)

sudo apt-get install openjdk-7-jre (to install version 7 of OpenJDK)

Install only the Java versions you need. When After this appears on the screen , xx MB of disk space will be occupied. To continue? [Y / n] , type Y and press Enter to complete the operation.

At the end of the operation, to check that everything went smoothly, give the java -version command in the Terminal to find out which versions of Java are installed on your computer. An openjdk version “1.8.0_xx-internal” type should appear .

If you have installed multiple versions of OpenJDK in Ubuntu and want to set one as default, use one of the following commands (as also illustrated in the previous chapter of this tutorial).

sudo update-alternatives --config java (to choose the default Java interpreter)

sudo update-alternatives --config javac (to choose the default Java compiler)

If any passage of the guide is not clear to you or you are unable to install Java Ubuntu , ask for help on the official Ubuntu Italia forum , there you will find many users ready to help you out.