How to Set Up a Java Development Environment on Arch Linux

How to Set Up a Java Development Environment on Arch Linux

Setting up a robust Java development environment on Arch Linux requires a combination of installing the correct packages, configuring the development tools, and optionally setting up an Integrated Development Environment (IDE) for increased productivity. Arch Linux’s rolling release model and access to the Arch User Repository (AUR) make it a flexible and powerful platform for software development, including Java.

In this article, we’ll walk through the complete process of setting up a Java development environment on Arch Linux, covering:

  • Installing Java Development Kits (JDKs)
  • Setting environment variables
  • Installing build tools (Maven, Gradle)
  • Setting up an IDE (Eclipse or IntelliJ IDEA)
  • Running your first Java application

1. Installing Java Development Kit (JDK)

Java applications are typically developed using a Java Development Kit (JDK), which includes the Java Runtime Environment (JRE) and development tools such as the Java compiler (javac).

Step 1: Choose a JDK

Arch Linux provides access to multiple JDK versions through the official repositories and the AUR. The most common options include:

  • jdk-openjdk (OpenJDK)
  • jdk11-openjdk (Java 11)
  • jdk17-openjdk (Java 17 LTS)
  • jdk8-openjdk (Java 8 LTS)
  • Oracle JDK (AUR: jdk, jdk11, etc.)

For most users, jdk-openjdk (which installs the latest LTS) is a good starting point.

Step 2: Install OpenJDK

To install the latest OpenJDK:

sudo pacman -S jdk-openjdk

To install a specific version (e.g., Java 17):

sudo pacman -S jdk17-openjdk

Step 3: Verify Installation

Check the installed version:

java -version

Check the compiler version:

javac -version

You should see output indicating the installed version of Java and the compiler.


2. Setting JAVA_HOME Environment Variable

Setting JAVA_HOME helps many Java-based tools and IDEs locate the Java installation directory.

Step 1: Find Java Installation Path

To find where Java is installed:

archlinux-java status

This will show the installed versions and the default one in use, such as:

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

Find its path:

readlink -f /usr/lib/jvm/default

Step 2: Set JAVA_HOME

You can define JAVA_HOME globally in /etc/environment or for your user only.

Option 1: Set JAVA_HOME for Current User

Add the following to ~/.bashrc, ~/.zshrc, or your preferred shell configuration file:

export JAVA_HOME="/usr/lib/jvm/java-17-openjdk"
export PATH="$JAVA_HOME/bin:$PATH"

Apply changes:

source ~/.bashrc

Option 2: Set JAVA_HOME Globally

Edit /etc/environment and add:

JAVA_HOME="/usr/lib/jvm/java-17-openjdk"

Then log out and log back in to apply.


3. Installing Java Build Tools

3.1 Apache Maven

Maven is a build automation tool widely used in Java projects.

Install it with:

sudo pacman -S maven

Verify:

mvn -version

3.2 Gradle

Gradle is a modern build tool favored for Android development and some Java projects.

Install with:

sudo pacman -S gradle

Verify:

gradle -v

4. Setting Up an IDE

Although you can use a text editor and the terminal to write and compile Java code, using an IDE significantly enhances productivity with features like autocomplete, debugging, refactoring, and project templates.

4.1 IntelliJ IDEA

IntelliJ IDEA is one of the most popular IDEs for Java development.

Install via AUR

You can install the Community Edition (open-source) using an AUR helper like yay:

yay -S intellij-idea-community-edition

For the Ultimate Edition (commercial):

yay -S intellij-idea-ultimate-edition

After installation, you can launch it via your application launcher or the idea command.

4.2 Eclipse IDE

Eclipse is a well-known open-source IDE for Java and other languages.

Install Eclipse

sudo pacman -S eclipse-java

Launch Eclipse:

eclipse

4.3 Visual Studio Code (Optional)

VS Code is lightweight and supports Java via extensions.

sudo pacman -S code

Install the following extensions from the marketplace:

  • “Extension Pack for Java”
  • “Language Support for Java(TM) by Red Hat”
  • “Debugger for Java”

5. Writing and Running Your First Java Application

Let’s test our setup by writing a simple “Hello World” application.

Step 1: Create a New Directory

mkdir ~/java-projects/hello
cd ~/java-projects/hello

Step 2: Create the Java File

Create HelloWorld.java:

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

Save the file.

Step 3: Compile the Program

javac HelloWorld.java

This creates a HelloWorld.class file in the directory.

Step 4: Run the Program

java HelloWorld

You should see:

Hello, Arch Linux!

6. Managing Multiple Java Versions

If you need to work with multiple versions of Java, Arch Linux makes this simple.

Step 1: Install Additional JDKs

You can install multiple versions, such as:

sudo pacman -S jdk11-openjdk jdk8-openjdk

Step 2: Use archlinux-java

List all installed JDKs:

archlinux-java status

Set a different default version:

sudo archlinux-java set java-11-openjdk

Check that it changed:

java -version

7. Optional: Use SDKMAN! for Java Toolchain Management

SDKMAN! is a great tool for managing parallel versions of multiple Java SDKs and related tools like Maven and Gradle.

Install SDKMAN

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

Install Java, Maven, and Gradle

sdk install java
sdk install maven
sdk install gradle

You can switch between installed versions easily using:

sdk use java <version>

Conclusion

Setting up a Java development environment on Arch Linux is straightforward thanks to the flexibility of the Arch ecosystem and the comprehensive package availability. Whether you are working on desktop apps, web apps, or Android development, this setup provides a solid foundation.

By combining OpenJDK, build tools like Maven or Gradle, and a robust IDE such as IntelliJ IDEA or Eclipse, you are ready to build modern Java applications efficiently. For users requiring multiple JDKs, Arch’s native tooling and SDKMAN! offer clean version management.

With this environment ready, you’re all set to explore Java development on Arch Linux—be it for learning, prototyping, or professional software engineering.