Java 21 on Devuan 5 (Debian 12): Install manually
Tags: java, openjdk, devuan, debian
Published: 2023-10-14 10:34:58

## Summary

Around [Java](https://dev.java/), the general-purpose programming language, the next LTS (Long Term Support) version of [OpenJDK](https://openjdk.org/), [21](https://jdk.java.net/21/), was released last month, on 17 Sep. 2023 🎉

On [Debian](https://www.debian.org/) [12 - bookworm](https://www.debian.org/releases/bookworm/) [repositories](https://packages.debian.org/bookworm/), the current version is 17 aka the previous LTS.

This post shows how to install 21 manually on [Devuan](https://www.devuan.org/) [5 - Daedalus](https://www.devuan.org/os/announce/daedalus-release-announce-2023-08-14) based on Debian 12.

---

Alternatively, JDK 21 "[x64 Debian Package](https://www.oracle.com/java/technologies/downloads/#java21)" [Oracle](https://www.oracle.com/) offers is available.

In addition, Just in order to taste the latest, Oracle offers Java 21 [PlayGround](https://dev.java/playground/), too, which doesn't require local installation.

Moreover, one of the easiest ways is to use ["OpenJDK" Docker Official Image](https://hub.docker.com/_/openjdk) and its ["21-bookworm" tag](https://hub.docker.com/layers/library/openjdk/21-jdk/images/sha256-c67f402f77197f2e6ae84ff1fca868699ce3b38bfa78604524051420fa2e4383).

### Environment

- OS: Devuan 5 Daedalus
  - based on Debian 12 bookworm
- App Engine: OpenJDK 21

## Tutorial

### Get OpenJDK package

Visit: https://jdk.java.net/21/

You can get it there. I used the command line below:

```console
$ curl -LO https://download.java.net/java/GA/jdk21/fd2272bbf8e04c3dbaee13770090416c/35/GPL/openjdk-21_linux-x64_bin.tar.gz
```

You can verify the download by comparing the checksums between the server and the local. Use the command lines below, for example:

```console
$ echo "$(curl -s https://download.java.net/java/GA/jdk21/fd2272bbf8e04c3dbaee13770090416c/35/GPL/openjdk-21_linux-x64_bin.tar.gz.sha256) openjdk-21_linux-x64_bin.tar.gz" | \
      sha256sum -c
openjdk-21_linux-x64_bin.tar.gz: OK
```

It means it was confirmed that the server checksum was equal to the local one:

```console
$ # checksum of the downloaded file
$ sha256sum openjdk-21_linux-x64_bin.tar.gz
a30c454a9bef8f46d5f1bf3122830014a8fbe7ac03b5f8729bc3add4b92a1d0a  openjdk-21_linux-x64_bin.tar.gz
```

### Place files

Extract it:

```console
$ tar xzf openjdk-21_linux-x64_bin.tar.gz
```

The result is as below:

```console
$ ls {.,jdk-21}
.:
jdk-21  openjdk-21_linux-x64_bin.tar.gz

jdk-21:
bin  conf  include  jmods  legal  lib  release
```

Now you have `jdk-21` directory which contains `bin` etc. 👍

### Set environment variables

Prepare `PATH` and `JAVA_HOME`.

As to `PATH`:

```console
$ # case bash
$ export PATH=$(readlink -f ./jdk-21/bin):$PATH
$ # case fish
$ #set -x PATH $(readlink -f ./jdk-21/bin/):$PATH
```

As to `JAVA_HOME`:

```console
$ # case bash
$ export JAVA_HOME=$(readlink -f .)
$ # case fish
$ #set -x JAVA_HOME $(readlink -f .)
```

Ready 🙌

## Conclusion

Now Java 21 is in your hands:

```console
$ java --version
openjdk 21 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)
```

Let's do test run. Create a `.java` file:

```console
$ nvim HelloWorld.java
```

Write below in it:

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

The way to execute it directly is as below:

```console
$ java HelloWorld.java
Hello, world.
```

Yay. Next, try to compile it manually and run it:

```console
$ ls HelloWorld*
HelloWorld.java

$ javac HelloWorld.java
$ # .class file is generated

$ ls HelloWorld*
HelloWorld.class  HelloWorld.java

$ java HelloWorld
Hello, world.
```

Hello, the latest Java on the latest Devuan ☺