{"id":4461,"date":"2021-02-15T09:20:12","date_gmt":"2021-02-15T09:20:12","guid":{"rendered":"https:\/\/linuxways.net\/?p=4461"},"modified":"2021-02-15T09:20:15","modified_gmt":"2021-02-15T09:20:15","slug":"how-to-install-apache-maven-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-apache-maven-on-ubuntu-20-04\/","title":{"rendered":"How to Install Apache Maven on Ubuntu 20.04"},"content":{"rendered":"<p>Apache Maven is an open-source and free project management utility that is used for building and managing projects written in various languages. It is particularly used for the deployment of Java-based applications. It helps you to get all the necessary libraries that you need to build your application. This article explains how to install Apache Maven on the Ubuntu OS. There are following two ways to install Apache Maven on the Ubuntu system:<\/p>\n<ul>\n<li>Installing Apache Maven via apt<\/li>\n<li>Installing Apache Maven via .deb package<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: We have tested the commands and methods discussed here on <strong>Ubuntu 20.04 LTS<\/strong>. You must have sudo access to install\/remove the Apache Maven on your system.<\/p>\n<h2>Method 1: Installing Apache Maven via apt<\/h2>\n<p>In the following procedure, we are going to install Apache Maven via apt:<\/p>\n<p>1. Update system\u2019s repository index using the command below in Terminal:<\/p>\n<pre>$ sudo apt-get update<\/pre>\n<p>Enter the password for sudo.<\/p>\n<p>2. Then use the following command in order to install Apache Maven:<\/p>\n<pre>$ sudo apt-get install maven<\/pre>\n<p>Now you might be provided with <strong>the Y\/n<\/strong> option, press <strong>Y<\/strong> to carry on the installation of Apache Maven. Then the installation will be started on your system.<\/p>\n<p>3. Once the installation is completed, you can verify it by using the command below in Terminal:<\/p>\n<pre>$ mvn -version<\/pre>\n<p>After running the above command, you will receive the following similar output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"991\" height=\"147\" class=\"wp-image-4462\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-252.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-252.png 991w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-252-300x45.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-252-768x114.png 768w\" sizes=\"auto, (max-width: 991px) 100vw, 991px\" \/><\/p>\n<p>The above output also displays the installed version of Apache Maven which is <strong>3.6.3.<\/strong><\/p>\n<p>Now Apache Maven has been successfully installed and is ready to use.<\/p>\n<h2>Method 2: Installing Apache Maven from the official website<\/h2>\n<p>In the following procedure, we are going to download and install Apache Maven from its official website:<\/p>\n<p>1. Before installing Apache Maven, first you will need to install JDK. To install JDK, update the system repository index using the below command:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>Then install JDK as follows:<\/p>\n<pre>$ sudo apt install default-jdk<\/pre>\n<p>2. To verify if JDK has been installed, issue the below command in Terminal:<\/p>\n<pre>$ java --version<\/pre>\n<p>The following output verifies that JDK has been successfully installed on your system,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1023\" height=\"101\" class=\"wp-image-4463\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-253.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-253.png 1023w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-253-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-253-768x76.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-253-1020x101.png 1020w\" sizes=\"auto, (max-width: 1023px) 100vw, 1023px\" \/> 3. Now, you will need to download the <a href=\"https:\/\/maven.apache.org\/download.cgi\">Apache Maven<\/a> from its official website. Issue the command below in Terminal to download the most recent release:<\/p>\n<pre>$ wget <a href=\"https:\/\/downloads.apache.org\/maven\/maven-3\/3.6.3\/binaries\/apache-maven-3.6.3-bin.tar.gz\">https:\/\/downloads.apache.org\/maven\/maven-3\/3.6.3\/binaries\/apache-maven-3.6.3-bin.tar.gz<\/a> -P \/tmp<\/pre>\n<p>This command will save the downloaded Apache Maven archive file <strong>apache-maven-3.6.3-bin.tar.gz<\/strong> in the <strong>\/tmp<\/strong> directory.<\/p>\n<p>4. Now, extract the archive using the below command in Terminal:<\/p>\n<pre>$ tar -xvzf apache-maven-3.6.3-bin.tar.gz<\/pre>\n<p>This command will extract the file to the <strong>apache-maven-3.6.3<\/strong> directory.<\/p>\n<p>5. Now, copy the extracted directory <strong>apache-maven-3.6.3<\/strong> to <strong>\/opt\/<\/strong> as follows.<\/p>\n<pre>$ cp -r apache-maven-3.6.0 \/opt\/maven<\/pre>\n<p>6. Now, you will need to setup the environment variables. To do this, create a script file <strong>maven.sh<\/strong> in the <strong>\/etc\/profile.d<\/strong> directory using the below command in Terminal:<\/p>\n<pre>$ sudo nano \/etc\/profile.d\/maven.sh<\/pre>\n<p>Add the below lines in the script:<\/p>\n<pre>export JAVA_HOME=\/usr\/lib\/jvm\/default-java\n\nexport M2_HOME=\/opt\/maven\n\nexport MAVEN_HOME=\/opt\/maven\n\nexport PATH=${M2_HOME}\/bin:${PATH}<\/pre>\n<p>Now you can save and exit this script.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"540\" height=\"131\" class=\"wp-image-4464\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-254.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-254.png 540w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-254-300x73.png 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/p>\n<p>7. Now use the below command to give the script executable permissions:<\/p>\n<pre>$ sudo chmod +x \/etc\/profile.d\/maven.sh<\/pre>\n<p>8. Load the environment variables using the below command:<\/p>\n<pre>$ source \/etc\/profile.d\/maven.sh<\/pre>\n<p>Now the installation of Apache Maven has been completed. You can verify it by running the below command in Terminal:<\/p>\n<pre>$ mvn -version<\/pre>\n<p>After running the above command, you will receive the following similar output which verifies that Maven version 3.6.3 has been successfully installed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"994\" height=\"150\" class=\"wp-image-4465\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-255.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-255.png 994w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-255-300x45.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-255-768x116.png 768w\" sizes=\"auto, (max-width: 994px) 100vw, 994px\" \/><\/p>\n<h2>Uninstall Maven<\/h2>\n<p>In case you no longer need Maven on your system, you can easily <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-uninstall-programs-from-ubuntu-20-04-lts\/\">uninstall<\/a> it using the below command in Terminal:<\/p>\n<pre>$ sudo apt-get remove maven<\/pre>\n<p>By following any of the two methods discussed above, you can easily install Apache Maven on the Ubuntu system. We have also shared how to uninstall Apache Maven from Ubuntu if you ever need to do so.<\/p>","protected":false},"excerpt":{"rendered":"<p>Apache Maven is an open-source and free project management utility that is used for building and managing projects written in various languages. It is particularly used for the&hellip;<\/p>","protected":false},"author":4,"featured_media":4466,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-4461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4461","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\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4461"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4466"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}