How to install Java using apt-get

Java is a programming language that's specifically designed to be as platform independent as possible. Developers can write their applications once without the need to recompile a separate version of the application for each platform. The Advanced Packaging Tool is the most common method of installing Java on Debian Linux distributions such as Ubuntu. Apt simplifies software management on these systems by automating much of this process, including the download, configuration and installation of software packages. This example shows how to select a Java Development Kit (JDK) 7 installation package, install it with apt and verify that Java has been properly installed.

DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
TIME REQUIRED 15 min
RELATED PRODUCTS Ubuntu-based VPS or dedicated servers

Here is a quick tutorial on how to how to install Java using apt-get.

Select the Java package to install

Open a terminal window and login as root. Execute the following command to list the available OpenJDK packages that can install Java:

# apt-cache search openjdk

Select openjdk-7-jdk for this example, which is the OpenJDK 7 Development Kit.

Install OpenJDK

Enter this command to update the list of available packages from your remote repositories:

# apt-get update

Enter the following command to install the software package you have selected.

# apt-get install openjdk-7-jdk

Press 'y' when prompted to authorize the required storage space for the installation.

Verify that Java has been installed

This command provides the version of Java that was installed:

# java -version

The following screenshot shows that java 1.7.0_65 was installed in this example:


Was This Article Helpful?
Thank You For Your Feedback
Glad we helped! Anything more we can do for you?
Sorry about that. How can we be more helpful?