{"id":816,"date":"2024-04-03T16:58:01","date_gmt":"2024-04-03T16:58:01","guid":{"rendered":"https:\/\/techtutelage.net\/?p=816"},"modified":"2025-05-18T05:05:17","modified_gmt":"2025-05-18T05:05:17","slug":"how-to-install-java-on-debian-based-linux","status":"publish","type":"post","link":"https:\/\/techtutelage.net\/?p=816","title":{"rendered":"How to Install Java on Debian-based Linux"},"content":{"rendered":"\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/BW8LYA63jo8?si=7NL0xmPkWe3iNMun\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n\n\n<p>Java is a widely-used programming language and platform that powers numerous applications and systems worldwide. Installing Java on Debian-based Linux distributions like Ubuntu, Debian, and their derivatives is a straightforward process, but it involves a few essential steps. In this guide, I&#8217;ll walk you through the process of installing Java on your Debian-based Linux system.<\/p>\n\n\n\n<p><strong>Step 1: Checking Java Version<\/strong>. Before installing Java, it&#8217;s essential to check if Java is already installed on your system and determine its version. You can do this by running the following command in your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-3cda3f5bdeb0491f7d97a89461122449\">java -version<\/pre>\n\n\n\n<p>This command will display the installed Java version, if any.<\/p>\n\n\n\n<p><strong>Step 2: Find Available Java Versions. <\/strong>When navigating the available OpenJDK and OpenJRE versions on Debian-based Linux distributions, it&#8217;s important to note that both OpenJDK and OpenJRE are accessible options for Java installation. OpenJDK constitutes the entire Java Development Kit (JDK), encompassing both the runtime environment (JRE) and development tools, while OpenJRE solely pertains to the Java Runtime Environment.<\/p>\n\n\n\n<p>To explore the spectrum of available OpenJDK and OpenJRE versions, execute the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-b3bb8f2b1f2be281487f1a0e7d52c8df\">apt-cache search openjdk<\/pre>\n\n\n\n<p>This command generates a list of available OpenJDK and OpenJRE packages, presenting you with a selection to install either the JDK or JRE. While the JRE suffices for executing Java applications, opting for the JDK is advisable for development purposes or scenarios where access to development tools might be necessary.<\/p>\n\n\n\n<p>If you are unsure about precise requirements or anticipate future development needs, installing the JDK offers a more comprehensive solution.<\/p>\n\n\n\n<p><strong>Step 3: Installing Default JDK (Java Development Kit)<\/strong> To install the default Java Development Kit, execute the following command. To install the default Java Runtime Environment replace &#8220;<em><strong>jdk<\/strong><\/em>&#8221; in the command below with &#8220;<strong><em>jre<\/em><\/strong>&#8220;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-0a8cbb5ee0e697bcbb34fc1437641d7c\">sudo apt install default-jdk<\/pre>\n\n\n\n<p>This command installs the default JDK package. You can confirm successful installation of java by running the &#8220;<strong><em>java -version<\/em><\/strong>&#8221; command in your terminal.<\/p>\n\n\n\n<p><strong>Step 4: Installing Specific version of JDK or JRE<\/strong>. To install a specific version, such as OpenJDK 17, use the following command. Same as above, replace &#8220;<em><strong>jdk<\/strong><\/em>&#8221; in the command below with &#8220;<strong><em>jre<\/em><\/strong>&#8221; if you prefer to install OpenJRE 17 instead:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-ac92682e8efd6d675f14ed28a756e04d\">sudo apt install openjdk-17-jdk<\/pre>\n\n\n\n<p><strong>Step 5: Configuring Java Versions After installing multiple Java versions.<\/strong> You may need to configure which version should be used as the default. Use the following command to configure Java versions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-70f28ddb0c77651c5056b13e2f466bce\">sudo update-alternatives --config java<\/pre>\n\n\n\n<p>This command allows you to select the default Java Runtime Environment.<\/p>\n\n\n\n<p><strong>Step 6: Configuring Java Compiler. <\/strong>Similarly, if you have installed multiple versions of JDK you can configure the default Java compiler using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-7ff8b32cd7c8d6d07b88aec21315c5fe\">sudo update-alternatives --config javac<\/pre>\n\n\n\n<p><strong>Step 7: Downloading and Installing Oracle JDK (Optional)<\/strong><\/p>\n\n\n\n<p>In instances where the specific version of Java Development Kit (JDK) you require isn&#8217;t available in the default repository, you can obtain it directly from Oracle&#8217;s website and install it manually. Here&#8217;s how you can do it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-b516b2ddeded458f5d9d18dfebc8945e\">wget https:\/\/download.oracle.com\/java\/22\/latest\/jdk-22_linux-x64_bin.deb<br>sudo dpkg -i jdk-22_linux-x64_bin.deb<br>sudo apt -f install<\/pre>\n\n\n\n<p>These commands download the Oracle JDK package and install it using dpkg.<\/p>\n\n\n\n<p><strong>Step 8: Setting JAVA_HOME (Optional) <\/strong>Setting the JAVA_HOME environment variable is optional but can be useful for specifying the Java installation directory. You can set JAVA_HOME in your ~\/.bashrc (for user specific setup) file or \/etc\/environment <strong>(for system wide setup)<\/strong> file by opening either file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-241fa035d8f1fb2bc2847dcfe440e50c\">nano ~\/.bashrc <\/pre>\n\n\n\n<p>or,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-f0560b0e5767c83a3ab8c97dbf093f88\">nano \/etc\/environment <\/pre>\n\n\n\n<p>And adding the following line. You can get the path for the desired Java version by running the &#8220;<em><strong>sudo update-alternatives &#8211;config java<\/strong><\/em>&#8221; command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-7a7ed0b32f540dfceeee7216494d2873\">export JAVA_HOME=\/path\/to\/java<\/pre>\n\n\n\n<p>Save the file and reload for the changes to take effect.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-04f6dd1ed07245fc6f10bed45020288c\">source ~\/.bashrc <\/pre>\n\n\n\n<p>or,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-97c696a6ec0794fc50d26daca4669702\">source \/etc\/environment <\/pre>\n\n\n\n<p><strong>Conclusion:<\/strong> By following the steps outlined in this guide, you can successfully install Java on your Debian-based Linux system using various methods. Whether you opt for OpenJDK or Oracle JDK, you now have the knowledge to set up Java according to your preferences and requirements. Java&#8217;s versatility and wide range of applications make it an essential tool for developers and users alike on Linux platforms.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java is a widely-used programming language and platform that powers numerous applications and systems worldwide. Installing Java on Debian-based Linux distributions like Ubuntu, Debian, and their derivatives is a straightforward process, but it involves a few essential steps. In this guide, I&#8217;ll walk you through the process of installing Java on your Debian-based Linux system. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-816","post","type-post","status-publish","format-standard","hentry","category-tutorials","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts\/816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=816"}],"version-history":[{"count":2,"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts\/816\/revisions"}],"predecessor-version":[{"id":818,"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts\/816\/revisions\/818"}],"wp:attachment":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}