Welcome to this guide on how to install Java 23 (OpenJDK 23) on Linux Mint 21. But before we dive into the nub of this guide, we will take a look at what Java is and the features of this latest release of Java, Java 23. Java is one of the world’s popular high-level, object-oriented programming languages used by developers around the world to write once and run everywhere. The word “write once and run everywhere” here means that a compiled Java code is capable of running on all platforms supporting Java without the need to recompile. JDK an abbreviation of Java Development Kit contains many tools including JRE(Java Runtime Environment), Javac, Java, Jar e.t.c
Java 23, released on 17th September 2024, is the latest release of the Java SE platform. It comes packed with the following cool features:
- Console Methods With Explicit Locale: Users can now output the string or display the prompt text formatted with the specified
Locale
, which may be independent of the default locale. - Thread and Timestamp Options for
java.security.debug
System Property: Thejava.security.debug
system property now accepts arguments which add thread ID, thread name, caller information, and timestamp information to debug statements for all components or a specific component. - The “KeychainStore” of the Apple provider now supports two types of keystores:
- “KeychainStore” which contains private keys and certificates for the user’s current keychain
- “KeychainStore-ROOT” which contains certificates from the system root certificates keychain
- A new suboption is provided for the
javac
-Xlint
option, to detect issues related to the placement of documentation comments in source code. - Improve Structural Navigation in API Documentation: API documentation generated by the standard doclet now comes with enhanced navigation features, including a sidebar containing a table of contents for the current page, and breadcrumb navigation for the current API element in the page header.
- The
javadoc --add-script
option now supports JavaScript modules in addition to conventional script files. Modules are detected automatically by inspecting the extension or content of the file passed as option argument. - Future JDK releases will continue to move towards making XML processing more restrictive by default. In order to help developers prepare for these changes, this release includes a JAXP Configuration File template,
$JAVA_HOME/conf/jaxp-strict.properties.template
, specifying more restrictive XML processing settings.
Having known the new features associated with Java 23, we are now set to commence the installation which consists of two different methods to get Java 23 LTS installed on your Linux Mint 21 system.
- OpenJDK
- Oracle JDK/JRE.
Option 1 : Install OpenJDK 23 on Linux Mint 21
The OpenJDK version of Java 23 is the free and open-source implementation of the Java SE platform. OpenJDK is available in the default Linux Mint 21 repositories but unfortunately, the available versions are not up-to-date. For us to be able to install the Open-source Java 23 LTS on Linux Mint, we are required to download the binary using the wget command below.
sudo wget https://download.java.net/java/GA/jdk23.0.2/6da2a6609d6e406f85c491fcb119101b/7/GPL/openjdk-23.0.2_linux-x64_bin.tar.gz
With the tarball downloaded, proceed and extract it with the command:
tar xvf openjdk-23.0.2_linux-x64_bin.tar.gz
Now move the extracted file to /opt/
:
sudo mv jdk-23.0.2 /opt/jdk-23
Now that the file exists in the /opt
directory, declare the environment variables as below.
$ sudo vim /etc/profile
export JAVA_HOME=/opt/jdk-23
export PATH=$PATH:$JAVA_HOME/bin
Now you can verify your set JAVA_HOME.
$ source /etc/profile
$ echo $JAVA_HOME
/opt/jdk-23
Check the installed version of Java.
$ java --version
openjdk 23.0.2 2025-01-21
OpenJDK Runtime Environment (build 23.0.2+7-58)
OpenJDK 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)
Option 2: Install Oracle JDK 23 on Linux Mint 21
This second option basically involves downloading and installing the production-ready Java 23 from the Java SE Downloads page and install using a similar technique as for method 1.
Download the binary release:
sudo wget https://download.oracle.com/java/23/latest/jdk-23_linux-x64_bin.tar.gz
Extract the downloded file to /opt
:
tar xvf jdk-23_linux-x64_bin.tar.gz
Now move the extracted file to /opt/
:
sudo mv jdk-23.0.2 /opt/jdk-23
Now that the file exists in the /opt
directory, declare the environment variables as below.
$ sudo vim /etc/profile
export JAVA_HOME=/opt/jdk-23
export PATH=$PATH:$JAVA_HOME/bin
Now you can verify your set JAVA_HOME.
$ source /etc/profile
$ echo $JAVA_HOME
/opt/jdk-23
Now check the installed version of java:
$ java -version
java version "23.0.2" 2025-01-21
Java(TM) SE Runtime Environment (build 23.0.2+7-58)
Java HotSpot(TM) 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)
Step 2. Set Default Java Version on Linux Mint 21
This setting is useful when you have multiple instances of Java installed on your Linux Mint 21 system.
List all the installed Java versions.
sudo update-alternatives --config java
Sample Output:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-23-oracle/bin/java 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
Select the version you want to set as the default version by typing the number as shown above. Then proceed and verify the set version.
$ java -version
java version "23.0.2" 2025-01-21
Java(TM) SE Runtime Environment (build 23.0.2+7-58)
Java HotSpot(TM) 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)
Step 3. Setting JAVA_HOME Environment Variable.
The JAVA_HOME environment is used by Java applications to determine the install location of Java as well as the version of Java to use when running the built applications.
This is achieved by editing the file at /etc/profile
.
sudo vim /etc/profile
In the file, you are required to add the Java path using the syntax below.
JAVA_HOME="/path/to/java/install"
For my case, the path will be as below normally gotten from the sudo update-alternatives --config java
command:
JAVA_HOME="/usr/lib/jvm/java-23-oracle"
For the changes made to apply, you are either required to log out and log in again or use the command below to source the environment.
source /etc/environment
Verify the JAVA_HOME set.
$ echo $JAVA_HOME
/usr/lib/jvm/java-23-oracle
Step 4. Test the Java Installation
Now that Java 23 has been installed on our Linux Mint 21 system, we need to test it using a simple HTML file created as below. I will name it Hello_World.java
.
cat > Hello_World.java <<EOF
public class helloworld {
public static void main(String[] args) {
System.out.println("Hello Java World from Kenya! Java 23 is amazing!");
}
}
EOF
Compile the Java Code.
java Hello_World.java
Output:
cloudspinx@Linux-Mint:~$ java Hello_World.java
Hello Java World from Kenya! Java 23 is amazing!
Conclusion.
Cheers! You have successfully installed Java 23 on Linux Mint 21. Additionally, we have set the default Java version and set the JAVA_HOME environment. I hope this guide was significant.
See more guides: