{"id":8079,"date":"2021-07-10T12:27:02","date_gmt":"2021-07-10T12:27:02","guid":{"rendered":"https:\/\/linuxways.net\/?p=8079"},"modified":"2021-07-10T12:27:02","modified_gmt":"2021-07-10T12:27:02","slug":"how-to-install-apache-maven-on-centos-8","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-install-apache-maven-on-centos-8\/","title":{"rendered":"How to Install Apache Maven on CentOS 8"},"content":{"rendered":"<p>Apache Maven is a powerful project management utility that uses the idea of project object model. It manages the project\u2019s build, dependency, reporting, and documentation. In an earlier post, we went through the <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-apache-maven-on-ubuntu-20-04\/\">installation of Apache Maven on Ubuntu OS<\/a>. Today\u2019s post is regarding how to install Apache Maven on CentOS. We will cover:<\/p>\n<ul>\n<li>Installing Apache Maven via Yum Package Manager<\/li>\n<li>Installing Apache Maven via Direct Download method<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: We will be demonstrating the procedure on <strong>CentOS 8.<\/strong><\/p>\n<h2>Installing Apache Maven via Yum Package Manager<\/h2>\n<p>Apache Maven is included in the CentOS default repository. In this procedure, we\u2019re going to install Apache Maven on CentOS via the Yum package manager.<\/p>\n<p>1. Use the command below in the Terminal to install Apache Maven on your CentOS system:<\/p>\n<pre>$ sudo yum install maven<\/pre>\n<p>Enter sudo password, after which the installation of Apache maven will be started.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"466\" class=\"wp-image-8080\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-210.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-210.png 803w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-210-300x174.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-210-768x446.png 768w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><\/p>\n<p>2. After the Apache Maven is installed, you can confirm it using this command:<\/p>\n<pre>$ mvn --version<\/pre>\n<p>The output below verifies that Apache version 3.5.4 has been installed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"863\" height=\"155\" class=\"wp-image-8081\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-211.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-211.png 863w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-211-300x54.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-211-768x138.png 768w\" sizes=\"auto, (max-width: 863px) 100vw, 863px\" \/><\/p>\n<h2>Installing Apache Maven via Direct Download<\/h2>\n<p>Apache Maven is also available for download and installation on its official website. In this method, we\u2019re going to install Apache Maven on the CentOS system. Using this method, you can have the latest release of Maven. We\u2019re going to download the current latest version 3.8.1 (as of July 2021).<\/p>\n<p>1. Apache maven requires JDK 1.7 or later to be installed on your machine. To verify if Java is installed, use the command below:<\/p>\n<pre>$ java --version<\/pre>\n<p>If it installed, you will see the below similar output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"613\" height=\"94\" class=\"wp-image-8082\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-212.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-212.png 613w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-212-300x46.png 300w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/p>\n<p>Otherwise, you can install it using the command below in the Terminal:<\/p>\n<pre>$ sudo yum install -y java-1.8.0-openjdk-devel<\/pre>\n<p>2. Visit the Apache Maven <a href=\"https:\/\/maven.apache.org\/download.cgi\">Downloads<\/a> page and download the latest or any previous version of Apache Maven. You can also use this command for downloading the Maven 3.8.1<\/p>\n<pre>$ wget <a href=\"https:\/\/downloads.apache.org\/maven\/maven-3\/3.8.1\/binaries\/apache-maven-3.8.1-bin.tar.gz\">https:\/\/downloads.apache.org\/maven\/maven-3\/3.8.1\/binaries\/apache-maven-3.8.1-bin.tar.gz<\/a><\/pre>\n<p>The downloaded file will be an archive file.<\/p>\n<p>3. Extract the downloaded Apache Maven archive using the command below:<\/p>\n<pre>$ sudo tar xf apache-maven-3.8.1-bin.tar.gz -C \/opt<\/pre>\n<p>Replace the <strong>apache-maven-3.8.1 <\/strong>with your extracted directory name.<\/p>\n<p>This command will extract the archive in a directory named <strong>apache-maven-3.8.1<\/strong> (apache-maven-version_number) in the <strong>\/opt<\/strong> directory.<\/p>\n<p>4. Move inside the \/opt directory and rename the extracted directory as follows:<\/p>\n<pre>$ cd \/opt<\/pre>\n<pre>$ sudo mv apache-maven-3.8.1\/ apache-maven<\/pre>\n<p>5. Now setup environment variable. To do so, create a file <strong>maven.sh<\/strong> in the <strong>\/etc\/profile.d <\/strong>using the command below.<\/p>\n<pre>$ sudo nano \/etc\/profile.d\/maven.sh<\/pre>\n<p>Now copy-paste the below lines in the <strong>maven.sh<\/strong> file:<\/p>\n<pre>export M2_HOME=\/opt\/apache-maven\r\n\r\nexport MAVEN_HOME=\/opt\/apache-maven\r\n\r\nexport PATH=${M2_HOME}\/bin:${PATH}<\/pre>\n<p>Then save the file and exit the editor.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"431\" height=\"125\" class=\"wp-image-8083\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-213.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-213.png 431w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-213-300x87.png 300w\" sizes=\"auto, (max-width: 431px) 100vw, 431px\" \/><\/p>\n<p>6. The <strong>maven.sh<\/strong> file created in the previous step is a script file. You will have to make it executable as follows:<\/p>\n<pre>$ sudo chmod +x \/etc\/profile.d\/maven.sh<\/pre>\n<p>7. Apply the configurations as follows:<\/p>\n<pre>$ source \/etc\/profile.d\/maven.sh<\/pre>\n<p>Now the Apache Maven has been installed. To verify the installation, use the command below:<\/p>\n<pre>$ mvn --version<\/pre>\n<p>The output below verifies that Apache maven version 3.8.1 has been installed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"861\" height=\"159\" class=\"wp-image-8084\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-214.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-214.png 861w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-214-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-214-768x142.png 768w\" sizes=\"auto, (max-width: 861px) 100vw, 861px\" \/><\/p>\n<h2>Uninstall Apache Maven<\/h2>\n<p>If you want to remove Apache Maven from your system, you can do so using the command below in the Terminal:<\/p>\n<pre>$ sudo yum remove maven<\/pre>\n<p>By following either of the installation methods( Yum package manager or via direct download method), you can easily install Apache Maven on CentOS. The Yum package manager downloads the older release of Maven while using the direct download method; you can have the latest version of Maven.<\/p>","protected":false},"excerpt":{"rendered":"<p>Apache Maven is a powerful project management utility that uses the idea of project object model. It manages the project\u2019s build, dependency, reporting, and documentation. In an earlier&hellip;<\/p>","protected":false},"author":1,"featured_media":8254,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[407,93],"class_list":["post-8079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-apache-maven","tag-centos-8"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8079","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=8079"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8079\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/8254"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=8079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=8079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=8079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}