How to Install Java Ubuntu

Are you taking your first steps in the world of Ubuntu and need help installing 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 contributions from Oracle and the open Java community.

Technically they don't differ much. Oracle's 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 applications and games in Java - both should be fine. That said, some software and some video games work better with Oracle's Java, so I'd tend to recommend that to you.

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 have fun!

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 (ex. openjdk version "1.8.0_xx-internal"), otherwise the message 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 key Submit on the PC keyboard you will have to type the password of your user account on Ubuntu (the one you use to log in to the system).

sudo apt-get purge openjdk *

At this point you need to communicate to Ubuntu the repository from which to draw the version of Java distributed by Oracle. He then returns to the terminal and give the following commands (the first is for adding Java in 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: number 8 or number 7. To tell the truth, Java 9 is also available, but 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

To install Java 8 on Ubuntu, open the terminal and give the following command.

sudo apt-get install oracle-java8-installer

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

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

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

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

Oracle Java 7 for 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 the right way, go back to the Terminal and give the command java -version. The writing should appear java version "1.7_xx".

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

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

How to Manage Java Installations

If you have installed multiple versions of Java on the same computer and you 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 type to set them as the default Java interpreter.

Then type the number corresponding to the version of Java you want to set as default (eg. 1 o 2), press the button Submit on your PC keyboard and that's it. If you want to set a Java version as your default compiler, use the command below.

sudo update-alternatives --config javac

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

sudo apt-get purge oracle-java7-installer (per disinstallare Java 7)

sudo apt-get purge oracle-java8-installer (per disinstallare Java 8)

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

Install OpenJDK on Ubuntu

Let's continue this guide on how to install java Ubuntu dealing with OpenJDK, the open source implementation of Java Standard Edition built by the open Java community and Oracle. To install OpenJDK on Ubuntu 14.10 and later, open the terminal and issue one of the following commands (install only the Java versions you need).

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

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

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

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

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

Purposes 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 commands from Terminal.

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

sudo apt-get update (to update the repository list)

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

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

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

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

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

At the end of the operation, to check that everything is spun the right way, give the command java -version in the Terminal to find out which versions of Java are installed on your computer. You should see something like this openjdk version "1.8.0_xx-internal".

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 explained 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 step of the guide is not clear to you or you are unable to install Java Ubuntu, ask for help on the official Ubuntu Italy forum, there you will find many users ready to give you a hand.