Install Java from your Linux distribution's repositories

Regardless of which distribution and package manager you prefer, it is easy to get Java on your Linux system.
20 readers like this.
What is your favorite open source Java IDE?

Pixabay. CC0.

There are a number of different ways to install Java on your Linux desktop. An obvious route is to use the packages provided in your Linux distribution. Note that this doesn’t work for everyone; for example, some users may need a very specific version of Java.

Before you can start, you must determine “which Java” you need. Do you just need to run some .class files or a .jar file? Or are you writing some code that you need to compile?

In my case, most of the Java I run is Java that I have (at least partly) written myself, so it always makes sense to install the full Java Development Kit, or JDK, which comes with a Java compiler, libraries, and some really useful utilities. And of course, hereabouts, we give preference to the open source JDK, called OpenJDK.

Since I primarily work on the Ubuntu Linux distribution, my package manager is apt. I can use apt to find out which OpenJDK packages are available:

apt list OpenJDK\*

The output of this command looks like:

Listing... Done
openjdk-11-dbg/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-dbg/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-demo/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-demo/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-doc/hirsute-updates,hirsute-updates,hirsute-security,hirsute-security 11.0.11+9-0ubuntu2 all
openjdk-11-jdk-headless/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-jdk-headless/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-jdk/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-jdk/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-jre-dcevm/hirsute 11.0.10+1-1 amd64
openjdk-11-jre-headless/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-jre-headless/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-jre-zero/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-jre-zero/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-jre/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 amd64
openjdk-11-jre/hirsute-updates,hirsute-security 11.0.11+9-0ubuntu2 i386
openjdk-11-source/hirsute-updates,hirsute-updates,hirsute-security,hirsute-security 11.0.11+9-0ubuntu2 all
openjdk-15-dbg/hirsute 15.0.3+3-1 amd64
openjdk-15-dbg/hirsute 15.0.3+3-1 i386
openjdk-15-demo/hirsute 15.0.3+3-1 amd64
...
openjdk-8-jre/hirsute-updates,hirsute-security 8u292-b10-0ubuntu1 i386
openjdk-8-source/hirsute-updates,hirsute-updates,hirsute-security,hirsute-security 8u292-b10-0ubuntu1 all

I have elided quite a few lines above with ....

It turns out that, even though I’m limiting myself to the OpenJDK, I still have plenty of options for:

  • The architecture (in my case, whether i386 or amd64).
  • The version of Java (in my case, whether 8, 11, 15, 16, 17).
  • The pure OpenJDK or the headless version.
  • The Java Runtime Environment or JRE.
  • Options for debugging, demo, source code, etc.

Again, in my case, primarily, I’m just interested in the pure vanilla OpenJDK.

Supposing then I want to install the Java 11 version of the plain vanilla OpenJDK for my amd64 architecture, I can type:

sudo apt install -a=amd64 openjdk-11-jdk

A few minutes later, I’ll be able to compile, run, debug, and package my Java code.

Note that it’s quite possible, and sometimes even desirable, to have multiple versions of Java installed simultaneously. In the case of Ubuntu, there is a useful utility called update-java-alternatives that displays and configures which java environment to use at any point in time.

Those of you using a different Linux distro can, in general, take a similar approach. Several other distros (such as Debian and Mint) also use apt, though the available packages may differ. Other distros use different package managers. For example, the Fedora documentation page for Installing Java shows how to use the Fedora dnf package manager to handle the installation. First, to show the available version, type:

dnf search openjdk

Next, to install the full development x86_64 architecture version, type:

sudo dnf install java-11-openjdk-devel.x86_64

Similarly, Fedora provides the alternatives utility to display and configure the Java environment.

For another example, the wonderful Arch Linux wiki shows the corresponding package is jdk11-openjdk. The wiki also explains many other important details related to using Java in Arch, such as using the archlinux-java utility to show what Java environments are installed or select a different default environment. Arch uses a package manager called pacman, which is also documented here on the Arch Linux wiki.

Regardless of which distribution and package manager you prefer, it is easy to get Java on your Linux system. Consider version and function, of course, before installing. Also keep in mind that there are options for managing two or more Java versions on the same computer. Most of my examples used apt, but keep in mind the dnf options, too.

What to read next
Tags
Chris Hermansen portrait Temuco Chile
Seldom without a computer of some sort since graduating from the University of British Columbia in 1978, I have been a full-time Linux user since 2005, a full-time Solaris and SunOS user from 1986 through 2005, and UNIX System V user before that.

Comments are closed.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.