Tyler Ideas

Aug 04, 2026 RAW
Article

How to Install Java on Ubuntu: A Step-by-Step Guide

Java, a powerful object-oriented programming language, is extensively used for developing diverse applications, ranging from Android apps to enterprise-level software. To harness its capabilities on Ubuntu, you must first install it on your system. This comprehensive guide will walk you through the straightforward process of installing Java on Ubuntu.

How To Install Java with Apt-Get on Ubuntu 16.04 | DigitalOcean
How To Install Java with Apt-Get on Ubuntu 16.04 | DigitalOcean

Before we dive into the installation process, ensure that your Ubuntu system is up-to-date. Open your terminal and run the following commands to update your system packages and perform a security upgrade:

How To Install Oracle Java 8 On Ubuntu Linux
How To Install Oracle Java 8 On Ubuntu Linux

Updating and Upgrading Ubuntu

Keeping your Ubuntu system up-to-date is crucial for a smooth Java installation process. Follow these two simple steps to update and upgrade your system:

How to Install Java in Ubuntu (Linux)
How to Install Java in Ubuntu (Linux)

sudo apt update

This command retrieves package lists from the repositories and updates them on your local system. Then, run the following command to install any available upgrades:

How to install Java JDK and JRE on Ubuntu 16.04,17.04
How to install Java JDK and JRE on Ubuntu 16.04,17.04

sudo apt upgrade

This command installs any available upgrades for your system packages.

Adding the OpenJDK PPAs

How to Install Java JDK 26 on Ubuntu Linux(2026)
How to Install Java JDK 26 on Ubuntu Linux(2026)

The Oracle Java Runtime Environment (JRE) and Java Development Kit (JDK) are no longer maintained by Oracle for Ubuntu systems. Instead, use OpenJDK, which is backed by multiple organizations and provides broad support for Linux distributions.

To add the OpenJDK PPA (Personal Package Archive) to your system, open your terminal and run the following command:

sudo add-apt-repository ppa:openjdk-r/ppa

How to Install Joomla on Ubuntu Linux: A Complete Guideline
How to Install Joomla on Ubuntu Linux: A Complete Guideline

Press ENTER to accept the prompt and complete the process.

Installing OpenJDK on Ubuntu

How to Install Oracle Java JDK via PPA on Ubuntu 16.04 byDA
How to Install Oracle Java JDK via PPA on Ubuntu 16.04 byDA
Ready to start your Java programming journey
Ready to start your Java programming journey
the home screen is open and ready to be used for windows xp or mac os
the home screen is open and ready to be used for windows xp or mac os
Install Oracle Java JDK/JRE 8 using Terminal  on Ubuntu 14.04 | 16.04
Install Oracle Java JDK/JRE 8 using Terminal on Ubuntu 14.04 | 16.04
the number nine is displayed next to an image of a computer screen with a logo on it
the number nine is displayed next to an image of a computer screen with a logo on it
Install Oracle Java 8 In Ubuntu Or Linux Mint Via PPA Repository [JDK8]
Install Oracle Java 8 In Ubuntu Or Linux Mint Via PPA Repository [JDK8]
How To Install JEdit Text Editor Application In Ubuntu Linux
How To Install JEdit Text Editor Application In Ubuntu Linux
Java Tutorial For Beginners | Java Installation in Windows 10 | How To Install Java JDK | SimpliCode
Java Tutorial For Beginners | Java Installation in Windows 10 | How To Install Java JDK | SimpliCode
how to install and install google chrome in ubuntu
how to install and install google chrome in ubuntu

Now that you have added the OpenJDK PPAs, it's time to install the Java Runtime Environment (JRE) and Java Development Kit (JDK) on your Ubuntu system. To install them, run the following commands:

sudo apt update

This command updates the package lists, ensuring that your system is aware of the new PPAs. Then, run the following command to install OpenJDK:

sudo apt install openjdk-11-jdk

Replace 11 with the desired Java version number. This command installs the OpenJDK for the specified version. You can verify the installation by running the following command:

javac -version

This command displays the version of the Java compiler (javac) installed on your system, confirming that Java is correctly installed.

Setting the JAVA_HOME Environment Variable

In some cases, you might need to set the JAVA_HOME environment variable for your system to recognize the installed Java version. Follow these steps to set the variable:

echo "export JAVA_HOME=/usr/lib/jvm/java-<version>-" >> ~/.bashrc

Replace <version> with the installed Java version, for example, 11.0.12. After adding the line, update your bash profile using the following command:

source ~/.bashrc

Now, your system is equipped with Java, and the JAVA_HOME environment variable is set. You can proceed with developing, executing, or testing your Java applications with confidence.

Congratulations! You have successfully installed Java on your Ubuntu system. Now that you have Java up and running, explore the extensive libraries, frameworks, and tools that Ubuntu offers to enhance your Java development experience. Happy coding!