If you’re a programmer, it’s likely you’ll have to install Java on your desktop or your laptop. After all, it’s one of the top programming languages used by developers, and there are many apps that depend on Java. In fact, there are actually three types of Java you can run, all of which work fine on Ubuntu. There’s the Java Runtime Environment, which is for consumers and lets you run Java apps; the Java Development Kit known as OpenJDK, which is open source and used by developers; and the Oracle Java, which is a licensed version of Java maintained by Oracle, the company that makes Java with additional features like Flight Recorder and Mission Control. To install two of these versions, you’ll have to use the terminal app in Ubuntu, but the other one is just as easy to install. We take a look at the process right here for you.
How to install the Java Runtime Environment
We begin with the Java Runtime Environment, which you need on Ubuntu to run Java programs. To install it, you’ll have to enter the terminal. Note that after each command we mention here, you’ll have to press Enter.
- Open Terminal with Ctrl + Alt + T
- Enter the following command:
sudo apt update
- Enter your password if prompted.
- Check to see if Java is installed by typing:
java -version
- If no Java is installed, type this command:
sudo apt install default-jre
- Enter your password.
- Type Y to confirm it, and then press Enter.
Once Java is installed, you can verify it is installed by typing out:
java -version
How to install OpenJDK
In this section, we’ll go over how to install the Java Development Kit, specifically the OpenJDK version. It’s a large group of files since it’s the development platform for building Java applications. You need this if you want to write or build Java apps and programs.
If you’re wondering, it is free and open source, meaning it is maintained by the community. There aren’t many major differences between the OpenJDK version and the Oracle JDK version we mention in the next section. The code changes are very similar, too
To get started, you’ll need the terminal again, and as a reminder, press Enter after each command.
- Open the terminal with Ctrl + Alt + T
- Enter the following command:
sudo apt update
- Enter your password if prompted.
- Enter the command:
sudo apt install default-jdk.
- Note this will grab the latest version of the Java Development Kit.
- If you want an older version, type out the following command. Just replace # with the version number you want to install. At the time of writing, the latest version number is 21.
sudo apt install openjdk-#-jdk.
- Type Y to confirm it, and then press Enter.
That’s it! You’ll now have the Java Development Kit installed on your system.
How to install Oracle Java with a DEB file
The final version of Java we want to go over is Oracle’s, which, of course, has some caveats. It’s a non-commercial version, so you have to be careful if you’re planning to make money off using it for coding apps. This method does not need the terminal since you’ll just be using a DEB file. Oracle JDK is closed source, though, so it has features restricted to paid licenses, like Flight Recorder and Mission Control.
- Open your web browser of choice.
- Download the version of Oracle Java you want to run.
- You can choose Java 17 or Java 21.
- When the download is complete, double-click to launch it.
- Click the green Install button.
- Enter your password.
Once the installation is complete, you’ll be able to see Oracle Java in your list of applications. If you want, you can also install it manually without going through the web browser by typing out the following commands, pressing Enter in between each line.
sudo apt install libc6-i386 libc6-x32 libxi6 libxtst6 -ywget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.deb sudo dpkg -i jdk-17_linux-x64_bin.deb
How to install Oracle Java with the terminal
If you’re more technical, you can also install Oracle using the terminal. Here’s what you can do.
- Run the command:
sudo apt install software-properties-common.
- Enter a password and press Y.
- Run the command:
sudo add-apt-repository ppa:linuxuprising/java -y
- Run the command:
sudo apt update
- Run the command:
sudo apt install oracle-java17-installer
- Press Tab, select OK, and then press Enter to confirm.
- Agree to the terms and press Tab to select Yes and then press Enter.
That’s pretty much all there is to installing Java on Ubuntu. If you want, you can set a default version of Java. To do this, type:
sudo update-alternatives --config java.
You’ll then be able to see the version numbers, and if you want to choose one, press the number listed and then Enter. Happy coding!
** (Disclaimer: This video content is intended for educational and informational purposes only) **