LinuxCommandLibrary

archlinux-java

Manage and switch Java environment implementations

TLDR

List installed Java environments

$ archlinux-java status
copy

Return the short name of the current default Java environment
$ archlinux-java get
copy

Set the default Java environment
$ archlinux-java set [java_environment]
copy

Unset the default Java environment
$ archlinux-java unset
copy

Fix an invalid/broken default Java environment configuration
$ archlinux-java fix
copy

SYNOPSIS

archlinux-java <command> [argument]

PARAMETERS

status
    Displays the currently active Java environment and lists all installed Java versions found on the system.

set <java_version_name>
    Sets the specified <java_version_name> as the default system-wide Java environment. The <java_version_name> must be one of the versions listed by archlinux-java status (e.g., java-17-jdk).

unset
    Removes the system-wide default Java environment by deleting the /usr/lib/jvm/default symlink. Applications might then rely on explicitly configured JAVA_HOME or system defaults from other sources.

fix
    Attempts to fix issues with the Java environment, primarily by recreating necessary symbolic links if they are broken or missing. This can be useful after system updates or package changes.

DESCRIPTION

archlinux-java is a utility exclusive to Arch Linux that provides a convenient way to manage multiple installed Java Development Kit (JDK) and Java Runtime Environment (JRE) versions. On Arch Linux, various Java packages (like jdk8, jdk11, jdk17, jre) can be installed simultaneously using pacman.

However, only one Java environment can be active system-wide at a time for commands like java, javac, and jar to resolve correctly. archlinux-java simplifies the process of switching between these installed versions. It primarily works by manipulating symlinks in /usr/lib/jvm/default, which then points to the desired Java installation. This allows developers and users to easily switch between different Java versions required by various applications or projects without manually altering PATH variables or symbolic links.

CAVEATS

archlinux-java only manages Java versions installed via pacman into the /usr/lib/jvm/ directory structure. It does not manage manual Java installations or those installed via other means (e.g., SDKMAN, direct tarball extractions into user directories).

Changes made by archlinux-java are system-wide. For per-user or per-project Java version management, tools like SDKMAN! or explicit JAVA_HOME environment variable settings are often preferred or used in conjunction with archlinux-java.

After changing the Java version, some applications or shell sessions might require a restart to pick up the new default.

JAVA PACKAGE NAMING

Arch Linux Java packages are typically named to indicate their major version (e.g., jdk8, jdk11, jdk17, jre). When using archlinux-java set, you provide the directory name (e.g., java-8-jdk, java-11-jdk, java-17-jdk, java-8-jre) which corresponds to the paths under /usr/lib/jvm/.

HOW IT WORKS

The script primarily manages the symlink at /usr/lib/jvm/default, which then points to the selected Java environment. Other system symlinks (e.g., /usr/bin/java, /usr/bin/javac) then point to components within /usr/lib/jvm/default/bin/, effectively making the selected Java version the system default.

HISTORY

archlinux-java is an essential part of the Arch Linux Java package ecosystem. Historically, managing multiple Java versions on Linux could be cumbersome, often involving manual symlink manipulation or complex environment variable setups. archlinux-java was introduced as a dedicated script to streamline this process specifically for Arch Linux users, providing a consistent and easy-to-use interface for switching between various JDK/JRE versions installed via pacman. It reflects Arch Linux's philosophy of providing simple yet powerful tools for system management.

SEE ALSO

java(1), javac(1), jar(1), pacman(8), update-alternatives(8)

Copied to clipboard