# Install Java

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/)
- [Overview](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/background/)
- [Create an Arm-based cloud virtual machine using Microsoft Cobalt 100 CPU](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/create-instance/)
- [Install Java](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/deploy/)
- [Java Baseline Testing](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/baseline/)
- [Benchmark using Java Microbenchmark Harness](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/benchmarking/)
- [Next Steps](https://learn.arm.com/learning-paths/servers-and-cloud-computing/java-on-azure/_next-steps/)

In this section, you will install Java on your Arm-based Ubuntu Pro virtual machine. The goal is to ensure you have both the Java Runtime Environment (JRE) for running Java applications and the Java Development Kit (JDK) for compiling code and running benchmarks.

## Install OpenJDK (JRE + JDK)

Use the Ubuntu package manager. The `default-jdk` package installs both the runtime and the compiler.

```bash
sudo apt update
sudo apt install -y default-jdk
```

## Verify your installation

Confirm the architecture and the installed Java versions:

```bash
uname -m
java -version
javac -version
```

You see the version information printed:

```
__output__ aarch64
__output__ openjdk version "21.0.8" 2025-07-15
__output__ OpenJDK Runtime Environment (build 21.0.8+9-Ubuntu-0ubuntu124.04.1)
__output__ OpenJDK 64-Bit Server VM (build 21.0.8+9-Ubuntu-0ubuntu124.04.1, mixed mode, sharing)
```

Check to ensure that the JDK is properly installed:

```bash
which java
which javac
```

The output should look similar to:

```
__output__ /usr/bin/java
__output__ /usr/bin/javac
```

Set the Java Environment Variables to point to the root directory of your JDK installation.

Use a text editor to edit the file `$HOME/.bashrc` and add the 2 environment variables.

```bash
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-arm64
export PATH=$JAVA_HOME/bin:$PATH
```

Source the updated `$HOME/.bashrc` file.

```bash
source ~/.bashrc
```

Confirm the new settings.

```bash
echo $JAVA_HOME
which java
which javac
```

The output is:

```
__output__ /usr/lib/jvm/java-21-openjdk-arm64
__output__ /usr/lib/jvm/java-21-openjdk-arm64/bin/java
__output__ /usr/lib/jvm/java-21-openjdk-arm64/bin/javac
```

**Note:** Ubuntu Pro 24.04 LTS provides OpenJDK 21 by default. Ensure your OpenJDK for Arm64 is **11.0.9 or newer** if you must run Java 11; releases before 11.0.9 can suffer performance issues due to false‑sharing cache contention. See the Arm community blog: [Java performance on Neoverse N1](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/java-performance-on-neoverse-n1). You can also consult the [Arm Ecosystem Dashboard](https://developer.arm.com/ecosystem-dashboard/) for package guidance on Arm Neoverse Linux systems.
