{"id":148339,"date":"2023-12-01T03:16:37","date_gmt":"2023-12-01T00:16:37","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=148339"},"modified":"2024-03-12T12:22:05","modified_gmt":"2024-03-12T09:22:05","slug":"install-java-jdk-or-openjdk-21-on-debian","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/install-java-jdk-or-openjdk-21-on-debian\/","title":{"rendered":"Install Java JDK 21 or OpenJDK 21 on Debian 12\/11\/10"},"content":{"rendered":"\n<p>Java is an open source, and high level programming language known to be reliable, robust and portable. It was originally created by Sun Microsystems in min-1990s but is now being owned and maintained by Oracle Corporation. Java is one of the widely adopted programming languages in banking, governments, schools and powering all types of <a href=\"https:\/\/computingforgeeks.com\/install-and-use-winget-windows-package-manager-client\/\">applications<\/a> worldwide.<\/p>\n\n\n\n<p><strong>Java Development Kit (JDK)<\/strong> can be described as a set of tools and libraries created by Oracle and other community contributors to enable you quickly develop Java applications. JDK includes Java Runtime Environment (JRE), a core engine for running Java applications, and extras such as debugger, compiler, and utilities that will increase your efficiency when programming.<\/p>\n\n\n\n<p>Every 3 years, Oracle will release an LTS version of Java programming language. The Long-Term Support (LTS) versions of Java get extended updates, bug fixes, security updates, and support from Oracle as opposed to the short term non-LTS releases. When using Java to develop mission critical applications in an enterprise and business setup, an LTS is very crucial for SLA and general stability.<\/p>\n\n\n\n<p>For those new to <strong>OpenJDK<\/strong>, it is a community driven and open-source implementation of Java Platform, Standard Edition (Java SE) specification. Being released under the open-source license means developers can modify and easily contribute to its source code. Most of the contributors are individuals and other private companies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing JDK 21 or OpenJDK 21 on Debian 12\/11\/10<\/h2>\n\n\n\n<p>In this installation, we will consider use of OpenJDK and the official Oracle JDK. When choosing between the two, factors like support, licensing are important. OpenJDK is a common choice since it&#8217;s open-source and ticks all the boxes in Java SE specification.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Install Oracle JDK 21 on Debian<\/h3>\n\n\n\n<p>The Oracle JDK is not fully open source implementation of Java SE specification. It is packaged with additional tools and features that are not available in the standard Java APIs. If your application needs support from Oracle on updates and security patches in a timely manner, then this is a better option for you.<\/p>\n\n\n\n<p><a href=\"https:\/\/computingforgeeks.com\/install-oracle-jdk-ubuntu\/\">Oracle JDK 21<\/a> can be downloaded from <a href=\"https:\/\/www.oracle.com\/java\/technologies\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oracle Downloads <\/a>pages. If you&#8217;re a CLI user, this can be downloaded using <code>wget<\/code> or <code>curl<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/download.oracle.com\/java\/21\/latest\/jdk-21_linux-x64_bin.deb<\/code><\/pre>\n\n\n\n<p>Once the package is downloaded, perform install with the <code>apt<\/code> or <code>dpkg<\/code> package management tool available for Debian users.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">sudo dpkg -i jdk-21_linux-x64_bin.deb<\/mark>\nSelecting previously unselected package jdk-21.\n(Reading database ... 34139 files and directories currently installed.)\nPreparing to unpack jdk-21_linux-x64_bin.deb ...\nUnpacking jdk-21 (21.0.1-ga) ...\nSetting up jdk-21 (21.0.1-ga) ...\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jar to provide \/usr\/bin\/jar (jar) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jarsigner to provide \/usr\/bin\/jarsigner (jarsigner) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/java to provide \/usr\/bin\/java (java) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/javac to provide \/usr\/bin\/javac (javac) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/javadoc to provide \/usr\/bin\/javadoc (javadoc) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/javap to provide \/usr\/bin\/javap (javap) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jcmd to provide \/usr\/bin\/jcmd (jcmd) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jconsole to provide \/usr\/bin\/jconsole (jconsole) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jdb to provide \/usr\/bin\/jdb (jdb) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jdeprscan to provide \/usr\/bin\/jdeprscan (jdeprscan) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jdeps to provide \/usr\/bin\/jdeps (jdeps) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jfr to provide \/usr\/bin\/jfr (jfr) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jhsdb to provide \/usr\/bin\/jhsdb (jhsdb) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jimage to provide \/usr\/bin\/jimage (jimage) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jinfo to provide \/usr\/bin\/jinfo (jinfo) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jlink to provide \/usr\/bin\/jlink (jlink) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jmap to provide \/usr\/bin\/jmap (jmap) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jmod to provide \/usr\/bin\/jmod (jmod) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jpackage to provide \/usr\/bin\/jpackage (jpackage) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jps to provide \/usr\/bin\/jps (jps) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jrunscript to provide \/usr\/bin\/jrunscript (jrunscript) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jshell to provide \/usr\/bin\/jshell (jshell) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jstack to provide \/usr\/bin\/jstack (jstack) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jstat to provide \/usr\/bin\/jstat (jstat) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jstatd to provide \/usr\/bin\/jstatd (jstatd) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/jwebserver to provide \/usr\/bin\/jwebserver (jwebserver) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/keytool to provide \/usr\/bin\/keytool (keytool) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/rmiregistry to provide \/usr\/bin\/rmiregistry (rmiregistry) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/serialver to provide \/usr\/bin\/serialver (serialver) in auto mode\nupdate-alternatives: using \/usr\/lib\/jvm\/jdk-21-oracle-x64\/lib\/jexec to provide \/usr\/bin\/jexec (jexec) in auto mode<\/code><\/pre>\n\n\n\n<p>Your JAVA HOME should be <strong><em>\/usr\/lib\/jvm\/jdk-21-oracle-x64\/<\/em><\/strong><\/p>\n\n\n\n<p>Check current default version of Java. If no old version it should show the one we just installed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">java --version<\/mark>\njava 21.0.1 2023-10-17 LTS\nJava(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)\nJava HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)<\/code><\/pre>\n\n\n\n<p>The <code>update-alternatives<\/code> command is used to update the default version of Java in systems with multiple versions.<\/p>\n\n\n\n<p>To list all installed versions of Java run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">sudo update-alternatives --list java<\/mark>\n\/usr\/lib\/jvm\/java-17-openjdk-amd64\/bin\/java\n\/usr\/lib\/jvm\/jdk-21-oracle-x64\/bin\/java<\/code><\/pre>\n\n\n\n<p>Example on setting to Java 21:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo update-java-alternatives --set  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\/usr\/lib\/jvm\/jdk-21-oracle-x64<\/mark><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Install OpenJDK 21 on Debian<\/h3>\n\n\n\n<p>This is a manual process which involves archive download, extracting and copying the files to a system&#8217;s directory.<\/p>\n\n\n\n<p>Go to&nbsp;<a href=\"https:\/\/jdk.java.net\/21\/\" target=\"_blank\" rel=\"noreferrer noopener\">OpenJDK 21 release&nbsp;<\/a>website and download a version suitable for your CPU architecture.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/download.java.net\/java\/GA\/jdk21.0.2\/f2283984656d49d69e91c558476027ac\/13\/GPL\/openjdk-21.0.2_linux-x64_bin.tar.gz<\/code><\/pre>\n\n\n\n<p>We can extract the file downloaded to get all files and directories containing OpenJDK.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar xvf openjdk-21.0.2_linux-x64_bin.tar.gz<\/code><\/pre>\n\n\n\n<p>Move created folder into <em>\/usr\/local\/<\/em> directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mv jdk-21.0.2\/ \/usr\/local\/jdk-21<\/code><\/pre>\n\n\n\n<p>To set Java environment, create a new source script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee -a  \/etc\/profile.d\/jdk21.sh&lt;&lt;EOF\nexport JAVA_HOME=\/usr\/local\/jdk-21\nexport PATH=\\$PATH:\\$JAVA_HOME\/bin\nEOF<\/code><\/pre>\n\n\n\n<p>Source to effect the change in your current shell session.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source \/etc\/profile.d\/jdk21.sh<\/code><\/pre>\n\n\n\n<p>Check Java version to verify it works.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">java --version<\/mark>\nopenjdk 21.0.2 2024-01-16\nOpenJDK Runtime Environment (build 21.0.2+13-58)\nOpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)<\/code><\/pre>\n\n\n\n<p>Choosing between OpenJDK and Oracle JDK has a high dependency on your application needs and long term company plans. In an ideal general use case, OpenJDK is an easy choice being 100% open source. But with Oracle JDK you can still use the free parts on small projects without the need for licensing.<\/p>\n\n\n\n<p>Until our paths intertwine again in content distribution channel, take care!.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java is an open source, and high level programming language known to be reliable, robust and portable. It was originally created by Sun Microsystems in min-1990s but is now being owned and maintained by Oracle Corporation. Java is one of the widely adopted programming languages in banking, governments, schools and powering all types of applications &#8230; <a title=\"Install Java JDK 21 or OpenJDK 21 on Debian 12\/11\/10\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/install-java-jdk-or-openjdk-21-on-debian\/\" aria-label=\"Read more about Install Java JDK 21 or OpenJDK 21 on Debian 12\/11\/10\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":148355,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,690,299,50,68,832],"tags":[38901,38898,38902],"class_list":["post-148339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","category-dev","category-how-to","category-linux-tutorials","category-programming","category-tech","tag-jdk-21","tag-openjdk-21","tag-openjdk-21-on-debian"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/148339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=148339"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/148339\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/148355"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=148339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=148339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=148339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}