Contents

Java 21 - how to install early_access version

I want to try Java 21!

Its easy!

You can easily try out the new features in Java 21 that I wrote about in the previous post. You don’t need to install anything. Just follow these steps:

  • Download and unzip the archive.
  • Set the JAVA_HOME variable to point to it.
  • Add the /bin subdirectory to your PATH variable.

Let’s do it step by step

Here’s how to do it in Ubuntu Linux:

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

You will find a list of packages to download: the jdk archive and the checksum file (sha256).

/en/posts/2023-07-02_instalacja_javy21/archiwa.png

Download the archive

Download .zip or .tar.gz appropriate for your operating system and architecture (and additionally download .sha256 for verification). In the commandline you an use wget with following options:

  • -c (continiue downloading to “partial” file)
  • -t0 (…retry again and again until you get it)
1
2
wget -ct0 https://download.java.net/java/early_access/jdk21/29/GPL/openjdk-21-ea+29_linux-x64_bin.tar.gz
wget -ct0 https://download.java.net/java/early_access/jdk21/29/GPL/openjdk-21-ea+29_linux-x64_bin.tar.gz.sha256

/en/posts/2023-07-02_instalacja_javy21/wget.png

Verify checksums

1
2
sha256sum  openjdk-21-ea+29_linux-x64_bin.tar.gz | sha256sum --check
openjdk-21-ea+29_linux-x64_bin.tar.gz: GOOD

Untar/unzip the archive

Untar or unzip the archive file which was downloaded in the previous step (either .zip or .tar.gz) to a local directory (for example, to ~/prog - this is your JDK location)

I downloaded .tar.gz file, so I need to extract it like this:

1
tar zxvf openjdk-21-ea+29_linux-x64_bin.tar.gz

Configure the environment

  • set your environment variable JAVA_HOME so that it points to JDK
  • add /bin subdirectory from your JDK installation to PATH

This is part of my shell configuration file (I use zsh):

/en/posts/2023-07-02_instalacja_javy21/cat_zshrc.png

1
2
export JAVA_HOME=$HOME/prog/jdk-21
export PATH=$CARGO_HOME:$DENO_HOME:$GRADLE_HOME:$SPRING_HOME:/snap/bin:$JAVA_HOME/bin:$PATH

Verify

Verify if everything works as it should

Check the version

1
2
3
4
~ java --version
openjdk 21-ea 2023-09-19
OpenJDK Runtime Environment (build 21-ea+29-2411)
OpenJDK 64-Bit Server VM (build 21-ea+29-2411, mixed mode, sharing)

Try to compile

Try to compile the simplest possible hello world java program :)

1
2
3
echo 'void main() {System.out.println("Hello, World");}' > Main.java && \
javac --enable-preview -source 21  Main.java && \
java --enable-preview Main

Summary

Installing Java for exploratory purposes is quite simple. If you don’t mind that - after following the above instructions - Java 21 will be the default Java version, don’t hesitate to give it a try. In September, you can expect Java 21 to be available in package managers. Once it’s officially released:

  • Return to these instructions.
  • Undo the changes (remove the downloaded and unzipped archive).
  • Install Java properly.
  • Update the environment variables :)

Happy coding!