How to Install OpenJDK 17 on Arch Linux

This guide walks through installing OpenJDK 17 on Arch Linux, from package selection to version switching and removal. Java 17 is widely used for building server applications, Android development toolchains, desktop applications, and running Java-based tools like Minecraft, Elasticsearch, and Jenkins. As an LTS release, OpenJDK 17 receives security updates through at least 2027, making it a stable choice for production environments.

Choose Your OpenJDK 17 Package

Arch Linux provides several OpenJDK 17 packages for different use cases. The packages are mutually exclusive within the same category, as smaller packages are subsets of larger ones.

PackageDescriptionBest For
jdk17-openjdkFull JDK with compiler, debugger, and toolsDevelopers building Java applications
jre17-openjdkRuntime with GUI support (AWT, Swing)Running desktop Java applications
jre17-openjdk-headlessMinimal runtime without GUI librariesServers, containers, CLI tools
openjdk17-docAPI documentationDevelopers needing offline Javadoc reference
openjdk17-srcOpenJDK source codeDebugging into JDK internals

For most users, install jdk17-openjdk because it includes everything needed to compile and run Java applications. The JDK package provides both the development kit and the runtime, so you do not need to install the JRE separately.

Update Arch Linux Before Installation

Synchronize package databases and upgrade installed packages before installing new software. Arch Linux is a rolling release distribution, so regular updates ensure package compatibility:

sudo pacman -Syu

Install OpenJDK 17 on Arch Linux

Install the Full Development Kit

Install the OpenJDK 17 development kit, which includes the Java compiler (javac), runtime, and development tools:

sudo pacman -S jdk17-openjdk

To include the API documentation for offline reference, add the documentation package:

sudo pacman -S openjdk17-doc

Alternative: Install Runtime Only

If you only need to run Java applications without compiling code, install the runtime environment instead:

sudo pacman -S jre17-openjdk

For servers or containers where GUI support is unnecessary, use the headless variant to minimize installed dependencies:

sudo pacman -S jre17-openjdk-headless

Verify the Installation

Confirm that Java 17 is installed and accessible from your terminal:

java -version

Expected output:

openjdk version "17.0.17" 2025-10-21
OpenJDK Runtime Environment (build 17.0.17+10)
OpenJDK 64-Bit Server VM (build 17.0.17+10, mixed mode, sharing)

If you installed the JDK, verify that the compiler is available:

javac -version

Expected output:

javac 17.0.17

Test OpenJDK 17 with a Sample Program

Verify that your Java installation can compile and execute code by creating a simple test program.

Create the Test File

Create a file named HelloWorld.java with the following content:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

You can create this file using any text editor. For example, using nano:

nano HelloWorld.java

Paste the code above, then save with Ctrl+O, press Enter, and exit with Ctrl+X.

Compile and Run

Compile the Java source file into bytecode:

javac HelloWorld.java

This creates a HelloWorld.class file in the same directory. Run the compiled program:

java HelloWorld

Expected output:

Hello, World!

If you see this output, OpenJDK 17 is correctly installed and functioning.

Switch Between Java Versions

When multiple Java versions are installed, Arch Linux provides the archlinux-java utility to switch between them. This command is part of the java-runtime-common package, which is installed as a dependency of any Java package.

List Installed Java Environments

Check which Java environments are installed and which one is currently active:

archlinux-java status

Example output with multiple Java versions installed:

Available Java environments:
  java-11-openjdk
  java-17-openjdk (default)
  java-21-openjdk

The environment marked (default) is the active Java version used when running java or javac commands.

Set the Default Java Version

Switch the default Java environment to OpenJDK 17:

sudo archlinux-java set java-17-openjdk

The environment name must match exactly as shown in the archlinux-java status output. Common environment names include:

  • java-8-openjdk for OpenJDK 8
  • java-11-openjdk for OpenJDK 11
  • java-17-openjdk for OpenJDK 17
  • java-21-openjdk for OpenJDK 21

Verify the Change

Confirm that the switch was successful:

java -version

The output should now show the Java version you selected.

Troubleshooting

Java Command Not Found

If running java -version returns “command not found”, verify that the package is installed:

pacman -Qi jdk17-openjdk

If the package is installed but the command still fails, check whether a default Java environment is set:

archlinux-java status

If no environment shows (default), set one manually:

sudo archlinux-java set java-17-openjdk

JAVA_HOME Not Set

Some applications require the JAVA_HOME environment variable. Arch Linux manages Java paths through symlinks in /usr/lib/jvm/, so JAVA_HOME is not required for most use cases. If an application specifically needs it, set the variable in your shell configuration:

echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk' >> ~/.bashrc
source ~/.bashrc

Verify the variable is set:

echo $JAVA_HOME

Expected output:

/usr/lib/jvm/java-17-openjdk

Wrong Java Version After Switching

If java -version shows an unexpected version after using archlinux-java set, the environment name may have been incorrect. Run archlinux-java status to see the exact names and try again with the correct spelling.

If the configuration appears corrupted, reset it:

sudo archlinux-java fix

This command repairs the default Java environment configuration.

Remove OpenJDK 17

To remove OpenJDK 17 and its dependencies, use the following command:

sudo pacman -Rns jdk17-openjdk

The -Rns flags remove the package (-R), its orphaned dependencies (-s), and configuration backup files (-n) for a complete cleanup.

If you installed the documentation or source packages, remove them separately:

sudo pacman -Rns openjdk17-doc openjdk17-src

For the runtime-only packages:

sudo pacman -Rns jre17-openjdk

Or for the headless runtime:

sudo pacman -Rns jre17-openjdk-headless

Verify that the package has been removed:

pacman -Qi jdk17-openjdk

Expected output confirming removal:

error: package 'jdk17-openjdk' was not found

If you have other Java versions installed, the system will automatically fall back to another available version. If OpenJDK 17 was your only Java installation, java commands will no longer work after removal.

Additional Resources

For more detailed information on Java configuration and troubleshooting on Arch Linux, refer to the Arch Wiki Java documentation. The wiki covers advanced topics including font rendering, HiDPI configuration, and application-specific fixes.

Conclusion

You now have OpenJDK 17 installed on Arch Linux with the ability to compile and run Java applications. The archlinux-java utility allows switching between multiple Java versions when needed, and the standard pacman removal commands provide a clean uninstall path. For ongoing development work, consider installing your preferred IDE or build tool (Maven, Gradle) to complement your Java environment.

Leave a Comment

Let us know you are human: