Install Java on Linux

Contents
Introduction
Install a JDK
Pick a Java version
JAVA_HOME
Check the version

Introduction

On Linux the easiest JDK comes from the distribution repositories. The package is usually called something like openjdk-17-jdk or java-17-openjdk-devel, depending on the distro.

Install a JDK

Debian and Ubuntu:

sudo apt update && sudo apt install -y openjdk-17-jdk

Rocky Linux and RHEL:

sudo dnf install -y java-17-openjdk-devel

Pick a Java version

Several JDKs can live side by side. List them and switch the default with the alternatives system:

sudo update-alternatives --config java

To install an older release, for example Java 8, ask for its package explicitly instead of the default one:

sudo apt install -y openjdk-8-jdk

JAVA_HOME

Build tools (Maven, Gradle) find the JDK through the JAVA_HOME variable. Point it at the installed JDK:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

To make it permanent, add the same line to ~/.bashrc or ~/.profile.

Check the version

java -version

A JDK answers with both the runtime and the compiler versions. javac -version must report the same release.

Related articles
Development на Java
Установка Java
Install Java on Linux
Install Java on FreeBSD
Install Java on macOS
Install Java on OpenBSD
Intellij
Компиляция и запуск Java кода
final
switch
Определить тип переменной
Генератор случайных чисел
Импорт из других классов
Maven
JUnit

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: