How to Install Java on Ubuntu

Java is a general-purpose programming language that can be used to develop a wide variety of applications. In order to start developing with Java or installing programs that require the Java Runtime Environment (JRE) to operate, you must first install Java and the Java Development Kit (JDK). As this process differs depending on your operating system, this article will focus on installing Java on Ubuntu via the command-line interface (CLI). For CentOS 7 users, please refer to this article. 

Topics Include: 

Install Java on your Dedicated Hosting server and start developing today!

Installing Java

In order to run Java-based software on your machine, you must first install the Java Runtime Environment. Installing the JRE will require use of the standard Ubuntu commands apt and apt-get to download and install the necessary software packages. 

  • Before installing Java, you will first want to check to see if it is already installed. To do this, run the following command:

    java -version
  • If it is not already installed, you can install Java with the following command:

    sudo apt-get install -y default-jre
  • Once the installation has finished, you can verify the installation with the following command:

    java -version
  • If the installation was successful, the output should look something like this:

    openjdk version "1.8.0_252"
    OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~16.04-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

Congratulations, you have now installed Java!

Installing the Java Development Kit (JDK)

If you are looking to use Java for development purposes, you will first need to install the Java Development Kit, which contains all of the necessary software required for developing Java-based applications.

  • To install the JDK, use the following command:

    sudo apt install default-jdk
  • Once the installation has finished, you can verify that installation with the following command:

    javac -version
  • If the installation was successful, the output should look as follows:

    javac 1.8.0_252

Congratulations, you are now prepared to start developing with Java on your Ubuntu machine! 

Alyssa Kordek Content Writer I

Alyssa started working for InMotion Hosting in 2015 as a member of the Technical Support team. Before being promoted to Technical Writer, Alyssa developed expertise in the fields of server hardware, Linux operating systems, cPanel, and WordPress. She now works to produce quality technical content featuring cutting-edge topics such as machine learning, data center infrastructure, and graphics card technology.

More Articles by Alyssa


It looks like this article doesn't have any comments yet - you can be the first. If you have any comments or questions, start the conversation!

Was this article helpful? Let us know!