Install Java on Ubuntu with Apt-Get

Installing Java with apt-get is easy. First, update the package index:

Then, check if Java is not already installed:

If it returns “The program java can be found in the following packages”, Java hasn’t been installed yet, so execute the following command:

This will install the Java Runtime Environment (JRE).

If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command: