HOWTO install Java on Ubuntu

From LinuxReviews
Jump to navigationJump to search

Installing Java so you can run .jar files and Java software on Ubuntu is really easy. All you have to do is to pick a version of OpenJDK which is suitable and install it. Here's how.

Why OpenJDK?[edit]

OpenJDK is the most widely used Java on Linux. It's included in the default repositories of all distributions. This makes it really easy to install compared to alternatives like Oracle's JDK.

There are many major version of OpenJDK available. Simply search for openjdk to see what major versions you can install. The default proposed by the distribution is named default-jre. To install it type:

Shell command(s):
sudo apt install default-jre

OpenJDK 11 is the default on Ubuntu Disco Dango.

Search to see what other versions are available:

Shell command(s):
sudo apt-cache search openjdk

This will list a lot of versions. If you want a newer version like OpenJDK 13 or an older version like OpenJDK 8 you can simply specify the -version-number and add -jre. To get 13 you would ask for:

Shell command(s):
sudo apt install openjdk-13-jre

You can check what, if any, Java version is installed by running java with -version as an option:

Shell command(s):
java -version

Java programs are generally distributed as .jar files. You can run them with

Shell command(s):
java -jar Myprogram.jar

Good luck.