{"id":6409,"date":"2021-05-20T09:41:12","date_gmt":"2021-05-20T09:41:12","guid":{"rendered":"https:\/\/linuxways.net\/?p=6409"},"modified":"2021-05-20T09:41:12","modified_gmt":"2021-05-20T09:41:12","slug":"how-to-install-java-on-ubuntu-20-04-lts","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-java-on-ubuntu-20-04-lts\/","title":{"rendered":"How To Install Java on Ubuntu 20.04 LTS"},"content":{"rendered":"<p>There are a lot of Java applications that you may come across and use in your daily work. That\u2019s why you need JVM (Java\u2019s virtual machine) as the run-time environment to run Java applications.<\/p>\n<p>This tutorial will show you how to install Java Run-time Environment (JRE) and the Java Developer Kit (JDK) on Ubuntu 20.04 needed by many Java-based applications.<\/p>\n<h2>Installing the Default JRE in Ubuntu<\/h2>\n<p>We will install OpenJDK 11, which is an open-source alternative to the JRE and JDK.<\/p>\n<p>First, we update the system with:<\/p>\n<pre>$ sudo apt update &amp;&amp; sudo apt upgrade<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1080\" class=\"wp-image-6410\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-93.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-93.png 1920w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-93-300x169.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-93-1024x576.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-93-768x432.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-93-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>Now we will check if the Java Run-time Environment is installed on the system:<\/p>\n<pre>$ java -version<\/pre>\n<p>If Java is not installed on your system you will get the command not found error:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"82\" class=\"wp-image-6411\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-94.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-94.png 970w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-94-300x25.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-94-768x65.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/p>\n<h2>Installing Java Runtime Environment (JRE)<\/h2>\n<p>Now we will install OpenJDK 11, which will provide Java Runtime Environment (JRE). Type the following command to install the packages:<\/p>\n<pre>$ sudo apt install default-jre<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1080\" class=\"wp-image-6412\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-95.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-95.png 1920w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-95-300x169.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-95-1024x576.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-95-768x432.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-95-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>Type \u2018Y\u2019 to continue.<\/p>\n<p>After the packages are installed, type the java -version command again to verify the operation was successful:<\/p>\n<pre>$ java -version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1168\" height=\"107\" class=\"wp-image-6413\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-96.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-96.png 1168w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-96-300x27.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-96-1024x94.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-96-768x70.png 768w\" sizes=\"auto, (max-width: 1168px) 100vw, 1168px\" \/><\/p>\n<h2>Installing <strong>JDK <\/strong>(<strong>Java Development Kit<\/strong>)<\/h2>\n<p>After we have successfully installed Java Run-time Environment, we can now install Java Development Kit (JDK).<\/p>\n<p>Type the following command to install it:<\/p>\n<pre>$ sudo apt install default-jdk<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1825\" height=\"548\" class=\"wp-image-6414\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-97.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-97.png 1825w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-97-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-97-1024x307.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-97-768x231.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-97-1536x461.png 1536w\" sizes=\"auto, (max-width: 1825px) 100vw, 1825px\" \/><\/p>\n<p>We can now verify the Java Development Kit installation by typing the following:<\/p>\n<pre>$ javac -version<\/pre>\n<p>If everything went ok, we should get the installed JDK version:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"629\" height=\"59\" class=\"wp-image-6415\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-98.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-98.png 629w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-98-300x28.png 300w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>Next, we need to set up the JAVA_HOME environment variable.<\/p>\n<h2><strong>Setting the JAVA_HOME Environment Variable<\/strong><\/h2>\n<p>The JAVA_HOME environment variable is used to discover the Java installation directory by Java-based applications.<\/p>\n<p>First, we must check in which directory the Java is installed:<\/p>\n<pre>$ readlink -f \/usr\/bin\/java<\/pre>\n<pre>\/usr\/lib\/jvm\/java-11-openjdk-amd64\/bin\/java<\/pre>\n<p>Now open <strong>\/etc\/environment<\/strong> file using your favorite text editor:<\/p>\n<pre>$ sudo nano \/etc\/environment<\/pre>\n<p>Now add the following line to the end of the file, after replacing the path with the installation directory path on your system that you\u2019ve got by running the previous command readlink, but omit \/bin\/java at the end:<\/p>\n<pre><strong>JAVA_HOME=\u201d\/usr\/lib\/jvm\/java-11-openjdk-amd64\u201d<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1509\" height=\"132\" class=\"wp-image-6416\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-99.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-99.png 1509w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-99-300x26.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-99-1024x90.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-99-768x67.png 768w\" sizes=\"auto, (max-width: 1509px) 100vw, 1509px\" \/><\/p>\n<p>Save the file, then reload the configuration to your current session:<\/p>\n<pre>$ source \/etc\/environment<\/pre>\n<p>Now verify the environment path is updated by typing the following command:<\/p>\n<pre>$ echo $JAVA_HOME<\/pre>\n<pre>\/usr\/lib\/jvm\/java-11-openjdk-amd64<\/pre>\n<p>You should see the java path in the terminal output like in the example above.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In this tutorial, we have learned how to install Java Run-time Environment (JRE) and the Java Developer Kit (JDK) on Ubuntu 20.04 and the same steps are applicable on other Ubuntu versions as well.<\/p>","protected":false},"excerpt":{"rendered":"<p>There are a lot of Java applications that you may come across and use in your daily work. That\u2019s why you need JVM (Java\u2019s virtual machine) as the&hellip;<\/p>","protected":false},"author":1,"featured_media":6445,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[331,100],"class_list":["post-6409","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-java","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=6409"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6409\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/6445"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}