Chapter 2: How to install and configure the Java SE 21 LTS JDK for Debian, Ubuntu and MX-Linux.

Advertisement

Oracle announces the release of Java SE 21 with Extended Support LTS.

The latest long-term support release of Java offers thousands of updates, further enhancing the language and platform to help developers be more productive.

Java SE 21 (LTS): A New Era in Java Development

Introduction

Java SE 21 (LTS) is consolidating as one of the most significant and anticipated releases of the Java platform. With long-term support, this release offers stability and fundamental improvements for the development of enterprise applications and innovative projects. This document delves into Java SE 21, its evolution, the JDK, the new features introduced, its main features, and, finally, draws conclusions that highlight its impact on the Java ecosystem.

What is Java SE 21 (LTS)?

Java SE 21 is the latest version of the standard edition of Java, designed to provide a solid foundation and a robust development environment. The Long-Term Support (LTS) designation indicates that Oracle provides support and security updates for an extended period, which is essential for critical applications and long-term projects. This release reflects not only the natural evolution of the platform but also a response to current demands for performance, scalability, and maintainability in modern applications.

The JDK (Java Development Kit)

The JDK is the essential set of tools and libraries for developing, compiling, debugging, and running Java applications. In Java SE 21, the JDK has been updated and optimized to:

  • Improve performance: Integrating JVM-level improvements and new features to analyze and optimize memory usage.

  • Simplify development: With refined tools that make debugging, testing, and continuous integration easier.

  • Offer new APIs: That promote the development of more secure and robust applications.

These enhancements make the Java SE 21 JDK an ideal platform for developers looking to combine innovation with reliability in their projects.

What's new in Java SE 21

Among the major new features in Java SE 21 are:

  • Virtual Threads: This is, without a doubt, the most revolutionary feature. Virtual threads, which were previously in preview, are now final in this version. They allow for efficient management of millions of concurrent tasks, reducing the overhead associated with native threads and facilitating the scalability of web applications and distributed systems.

  • Sequenced Collections: New interfaces have been introduced such as SequencedCollection, SequencedSet and SequencedMapThese facilitate the management of collections with an explicit order, allowing easier access to the first or last element and simplifying the manipulation of complex data structures.

  • Language Improvements: Various features of the language have been polished, promoting the use of records with greater coherence, implementing improvements in pattern matching (for example, in switch statements) and optimizing the syntax to achieve more concise and readable code.

  • New APIs and Optimizations: Java SE 21 consolidates features previously in preview and launches new APIs aimed at improving both performance and security when manipulating data, resulting in a smoother and more robust development experience.

Main Features

Key features of Java SE 21 (LTS) include:

  • Long Term Support (LTS): A commitment to stability and continuous updates, ideal for mission-critical projects.

  • Virtual Threads: Improves concurrency by allowing large numbers of threads to run without the heavy overhead of native threads.

  • Sequenced Collections: They introduce intuitive APIs for managing ordered data structures, optimizing access and manipulation of elements.

  • Syntax and Language Improvements: With records, pattern matching and other optimizations make it easier to implement more readable and maintainable code.

  • New Performance and Security APIs: Incorporation of tools and methods that ensure optimal performance and greater robustness in data and process management.

These features not only boost developer productivity, but also enable the design of scalable and secure applications that adapt to the needs of modern and demanding markets.

Download and install Oracle JDK Java 21 LTS on your Linux operating system (Debian, Ubuntu, MX-Linux).

Download Oracle JDK Java 21 LTS in https://www.oracle.com/cl/java/technologies/downloads/

Java SE Development Kit 21.0.7 Downloads

JDK 21 binaries are free to use in production and can be redistributed at no cost, according to the Oracle's Free Terms and Conditions (NFTC).

Advertisement

JDK 21 will receive updates under the NFTC until September 2026, one year after the release of the next LTS. Subsequent updates to JDK 21 will be licensed under the Java SE OTN License (OTN), and production use beyond the limited free concessions of the OTN license will require the payment of a fee.

Next, download the package x64 deb binary for easy installation of Oracle Java JDK 21 (LTS):

// Oracle Java JDK 17 
$ wget -q https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb 
// Instalar Oracle Java JDK 21 
$ sudo dpkg -i jdk-21_linux-x64_bin.deb
Seleccionando el paquete jdk-21 previamente no seleccionado.
(Leyendo la base de datos ... 437118 ficheros o directorios instalados actualmente.)
Preparando para desempaquetar jdk-21_linux-x64_bin.deb ...
Desempaquetando jdk-21 (21.0.7-ga) ...
Configurando jdk-21 (21.0.7-ga) ...
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jar para proveer /usr/bin/jar (jar) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jarsigner para proveer /usr/bin/jarsigner (jarsigner) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java para proveer /usr/bin/java (java) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/javac para proveer /usr/bin/javac (javac) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/javadoc para proveer /usr/bin/javadoc (javadoc) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/javap para proveer /usr/bin/javap (javap) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jcmd para proveer /usr/bin/jcmd (jcmd) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jconsole para proveer /usr/bin/jconsole (jconsole) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jdb para proveer /usr/bin/jdb (jdb) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jdeprscan para proveer /usr/bin/jdeprscan (jdeprscan) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jdeps para proveer /usr/bin/jdeps (jdeps) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jfr para proveer /usr/bin/jfr (jfr) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jhsdb para proveer /usr/bin/jhsdb (jhsdb) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jimage para proveer /usr/bin/jimage (jimage) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jinfo para proveer /usr/bin/jinfo (jinfo) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jlink para proveer /usr/bin/jlink (jlink) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jmap para proveer /usr/bin/jmap (jmap) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jmod para proveer /usr/bin/jmod (jmod) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jpackage para proveer /usr/bin/jpackage (jpackage) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jps para proveer /usr/bin/jps (jps) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jrunscript para proveer /usr/bin/jrunscript (jrunscript) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jshell para proveer /usr/bin/jshell (jshell) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jstack para proveer /usr/bin/jstack (jstack) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jstat para proveer /usr/bin/jstat (jstat) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jstatd para proveer /usr/bin/jstatd (jstatd) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/jwebserver para proveer /usr/bin/jwebserver (jwebserver) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/keytool para proveer /usr/bin/keytool (keytool) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/rmiregistry para proveer /usr/bin/rmiregistry (rmiregistry) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/serialver para proveer /usr/bin/serialver (serialver) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64 para proveer /usr/java/jdk-21-oracle-x64 (java_jdk_21_oracle) en modo automático
update-alternatives: utilizando /usr/lib/jvm/jdk-21.0.7-oracle-x64/lib/jexec para proveer /usr/bin/jexec (jexec) en modo automático

Next, we verify the Java installation by checking that it works on our system and confirming that it is the Oracle version of Java.

$ java --version
java 21.0.7 2025-04-15 LTS
Java(TM) SE Runtime Environment (build 21.0.7+8-LTS-245)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.7+8-LTS-245, mixed mode, sharing)

You may have multiple versions of Java installed on your system, you can switch and choose a different version.

After running this command, you will see a list of all installed Java versions, select the one you want to use by default:

$ sudo update-alternatives --config java

Existen 2 opciones para la alternativa java (que provee /usr/bin/java).

  Selección   Ruta                                         Prioridad  Estado
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java   352378880 modo automático
  1            /usr/lib/jvm/java-17-openjdk-amd64/bin/java   1711      modo manual
  2            /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java   352378880 modo manual

Pulse <Intro> para mantener el valor por omisión [*] o pulse un número de selección: 0

 

Simply enter a selection number to choose which Java executable should be used by default.

Setting Environment Variables in Java on Debian Linux

  • JAVA_HOME is used to tell your system where the JDK is installed.

  • PATH It is set up so that you can access Java executables without providing full paths each time.

  • CLASSPATH helps the JVM locate classes and libraries needed to run your applications.

At this point, you need to configure the Java environment variables on your Linux computer. To do this, you can use the following command:

$ cat <<EOF | sudo tee /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin 
export CLASSPATH=.:$JAVA_HOME/lib
EOF
export JAVA_HOME=/usr/java/default
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin:/bin export CLASSPATH=.:/lib

Then, apply the changes by getting your file with the following command:

$ source /etc/profile.d/jdk.sh

We check the creation of the environment variable script in Java.

$ cd /etc/profile.d/ 
$ ls jdk.sh
jdk.sh

We check that the Oracle JDK works and that the Java program compiler and interpreter respond.

We introduce 2 Java commands, the compiler (javac) and the Java interpreter (Java) to check that they respond on the command line.

// el compilador java
$ javac
Usage: javac <options> <source files>
where possible options include:
  @<filename>                  Read options and filenames from file
  -Akey[=value]                Options to pass to annotation processors
  --add-modules <module>(,<module>)*
        Root modules to resolve in addition to the initial modules,
        or all modules on the module path if <module> is ALL-MODULE-PATH.
  --boot-class-path <path>, -bootclasspath <path>
        Override location of bootstrap class files
  --class-path <path>, -classpath <path>, -cp <path>
        Specify where to find user class files and annotation processors
  -d <directory>               Specify where to place generated class files
  -deprecation
        Output source locations where deprecated APIs are used
  --enable-preview
        Enable preview language features.
        To be used in conjunction with either -source or --release.
  -encoding <encoding>         Specify character encoding used by source files
  -endorseddirs <dirs>         Override location of endorsed standards path
  -extdirs <dirs>              Override location of installed extensions
  -g                           Generate all debugging info
  -g:{lines,vars,source}       Generate only some debugging info
  -g:none                      Generate no debugging info
  -h <directory>
        Specify where to place generated native header files
  --help, -help, -?            Print this help message
  --help-extra, -X             Print help on extra options
  -implicit:{none,class}
        Specify whether to generate class files for implicitly referenced files
  -J<flag>                     Pass <flag> directly to the runtime system
  --limit-modules <module>(,<module>)*
        Limit the universe of observable modules
  --module <module>(,<module>)*, -m <module>(,<module>)*
        Compile only the specified module(s), check timestamps
  --module-path <path>, -p <path>
        Specify where to find application modules
  --module-source-path <module-source-path>
        Specify where to find input source files for multiple modules
  --module-version <version>
        Specify version of modules that are being compiled
  -nowarn                      Generate no warnings
  -parameters
        Generate metadata for reflection on method parameters
  -proc:{none,only,full}
        Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...]
        Names of the annotation processors to run;
        bypasses default discovery process
  --processor-module-path <path>
        Specify a module path where to find annotation processors
  --processor-path <path>, -processorpath <path>
        Specify where to find annotation processors
  -profile <profile>
        Check that API used is available in the specified profile.
        This option is deprecated and may be removed in a future release.
  --release <release>
        Compile for the specified Java SE release.
        Supported releases: 
            8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
  -s <directory>               Specify where to place generated source files
  --source <release>, -source <release>
        Provide source compatibility with the specified Java SE release.
        Supported releases: 
            8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
  --source-path <path>, -sourcepath <path>
        Specify where to find input source files
  --system <jdk>|none          Override location of system modules
  --target <release>, -target <release>
        Generate class files suitable for the specified Java SE release.
        Supported releases: 
            8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
  --upgrade-module-path <path>
        Override location of upgradeable modules
  -verbose                     Output messages about what the compiler is doing
  --version, -version          Version information
  -Werror                      Terminate compilation if warnings occur

// El intérprete java.
$ java
Usage: java [options] <mainclass> [args...]
           (to execute a class)
   or  java [options] -jar <jarfile> [args...]
           (to execute a jar file)
   or  java [options] -m <module>[/<mainclass>] [args...]
       java [options] --module <module>[/<mainclass>] [args...]
           (to execute the main class in a module)
   or  java [options] <sourcefile> [args]
           (to execute a single source-file program)

 Arguments following the main class, source file, -jar <jarfile>,
 -m or --module <module>/<mainclass> are passed as the arguments to
 main class.

 where options include:

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    --class-path <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -p <module path>
    --module-path <module path>...
                  A : separated list of elements, each element is a file path
                  to a module or a directory containing modules. Each module is either
                  a modular JAR or an exploded-module directory.
    --upgrade-module-path <module path>...
                  A : separated list of elements, each element is a file path
                  to a module or a directory containing modules to replace
                  upgradeable modules in the runtime image. Each module is either
                  a modular JAR or an exploded-module directory.
    --add-modules <module name>[,<module name>...]
                  root modules to resolve in addition to the initial module.
                  <module name> can also be ALL-DEFAULT, ALL-SYSTEM,
                  ALL-MODULE-PATH.
    --enable-native-access <module name>[,<module name>...]
                  modules that are permitted to perform restricted native operations.
                  <module name> can also be ALL-UNNAMED.
    --list-modules
                  list observable modules and exit
    -d <module name>
    --describe-module <module name>
                  describe a module and exit
    --dry-run     create VM and load main class but do not execute main method.
                  The --dry-run option may be useful for validating the
                  command-line options such as the module system configuration.
    --validate-modules
                  validate all modules and exit
                  The --validate-modules option may be useful for finding
                  conflicts and other errors with modules on the module path.
    -D<name>=<value>
                  set a system property
    -verbose:[class|module|gc|jni]
                  enable verbose output for the given subsystem
    -version      print product version to the error stream and exit
    --version     print product version to the output stream and exit
    -showversion  print product version to the error stream and continue
    --show-version
                  print product version to the output stream and continue
    --show-module-resolution
                  show module resolution output during startup
    -? -h -help
                  print this help message to the error stream
    --help        print this help message to the output stream
    -X            print help on extra options to the error stream
    --help-extra  print help on extra options to the output stream
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:jdwp
                  see also -agentlib:jdwp=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
                  HiDPI scaled images are automatically supported and used
                  if available. The unscaled image filename, e.g. image.ext,
                  should always be passed as the argument to the -splash option.
                  The most appropriate scaled image provided will be picked up
                  automatically.
                  See the SplashScreen API documentation for more information
    @argument files
                  one or more argument files containing options
    --disable-@files
                  prevent further argument file expansion
    --enable-preview
                  allow classes to depend on preview features of this release
To specify an argument for a long option, you can use --<name>=<value> or
--<name> <value>.

 

Remove jdk 17

If you want to uninstall the Oracle JDK Java 21 from the system, we will enter this command:

$ sudo dpkg -r jdk-17_linux-x64_bin.deb 
$ cd /etc/profile.d/ 
$ rm jdk.sh

Conclusion

Java SE 21 (LTS) marks a turning point in the evolution of the Java platform. Its long-term support not only ensures the stability and security required by enterprise projects but also promotes the adoption of innovations that boost performance and scalability. The definitive inclusion of virtual threads and new sequenced collections open up new possibilities for building robust, concurrent applications. Together, these improvements consolidate Java as a modern, flexible language, ready to meet the challenges of a constantly changing technological environment.

Summary

In short, Java SE 21 (LTS) is a revolutionary release that brings:

  • Guaranteed long-term support for critical applications.

  • Major technological innovations such as virtual threads and sequenced collections.

  • Language improvements and JDK updates improve performance and simplify development.

These features make Java SE 21 a must-have for developers looking to combine stability with the latest technological trends, reaffirming Java's position as a fundamental platform for modern software development.

Our score
Click to rate this post!
(Votes: 0 Average: 0)
Advertisement
Share on social media...

Deja un comentario

Your email address will not be published. Required fields are marked *

Basic information on data protection
ResponsibleJavier Cachón Garrido +info...
PurposeManage and moderate your comments. +info...
LegitimationConsent of the concerned party. +info...
RecipientsAutomattic Inc., USA to spam filtering. +info...
RightsAccess, rectify and cancel data, as well as some other rights. +info...
Additional informationYou can read additional and detailed information on data protection on our page política de privacidad.

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Scroll al inicio

Descubre más desde javiercachon.com

Suscríbete ahora para seguir leyendo y obtener acceso al archivo completo.

Seguir leyendo