{"id":9562,"date":"2021-08-23T14:55:29","date_gmt":"2021-08-23T14:55:29","guid":{"rendered":"https:\/\/linuxways.net\/?p=9562"},"modified":"2021-08-23T14:55:29","modified_gmt":"2021-08-23T14:55:29","slug":"how-to-install-apache-maven-on-rocky-linux-centos-8","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-install-apache-maven-on-rocky-linux-centos-8\/","title":{"rendered":"How to Install Apache Maven on Rocky Linux \/ CentOS 8"},"content":{"rendered":"<p>Written in Java and licensed under Apache License v2, <a href=\"https:\/\/maven.apache.org\/\">Apache Maven<\/a> is an open-source software project management and build tool that is tailored specifically for Java projects. In this guide, we look at how you can install Apache Maven on Rocky Linux 8.4.<\/p>\n<p>There are two ways of installing Apache Maven: you can install using the DNF \/ YUM package manager or install from the source binary package which gives you the latest version. We will look at each of the installation methods in turn.<\/p>\n<h2><strong>Method 1: Install Apache Maven using DNF \/ YUM package manager<\/strong><\/h2>\n<p>This is quite a straightforward way of installing Maven. However, be advised that this will not always give you the latest release of Maven. To install Apache Maven using DNF, run the command:<\/p>\n<pre><strong>$ sudo dnf install maven<\/strong><\/pre>\n<p>This installs Apache Maven and associated dependencies.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"901\" height=\"228\" class=\"wp-image-9563\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-470.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-470.png 901w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-470-300x76.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-470-768x194.png 768w\" sizes=\"auto, (max-width: 901px) 100vw, 901px\" \/><\/p>\n<p>To confirm the version of Apache version installed, execute the command:<\/p>\n<pre><strong>$ mvn --version<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"146\" class=\"wp-image-9564\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-471.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-471.png 960w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-471-300x46.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-471-768x117.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/p>\n<h2><strong>Method 2: Install the latest version of Apache Maven <\/strong><\/h2>\n<p>If getting the latest release of Apache Maven is your top priority, then installing from source is the way to go. This is accomplished by a series of steps as we shall see shortly.<\/p>\n<h3><strong>Step 1: Update the system<\/strong><\/h3>\n<p>First, update the packages on your system:<\/p>\n<pre><strong>$ sudo dnf update<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"231\" class=\"wp-image-9565\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-472.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-472.png 900w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-472-300x77.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-472-768x197.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/strong><\/p>\n<h3><strong>Step 2: Install OpenJDK<\/strong><\/h3>\n<p>Maven 3.3 and later versions require OpenJDK 1.7 and recent versions to install. We will install the latest LTS release which, at the moment, is OpenJDK 11. To achieve this, run the command:<\/p>\n<pre><strong>$ sudo dnf install java-11-openjdk-devel<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"229\" class=\"wp-image-9566\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-473.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-473.png 904w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-473-300x76.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-473-768x195.png 768w\" sizes=\"auto, (max-width: 904px) 100vw, 904px\" \/><\/strong><\/p>\n<p>To confirm the version of OpenJDK installed, run:<\/p>\n<pre><strong>$ java -version<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"121\" class=\"wp-image-9567\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-474.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-474.png 644w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-474-300x56.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/strong><\/p>\n<h3><strong>Step 3: Download Apache Maven archive <\/strong><\/h3>\n<p>The next step is to download Apache Maven. The latest version, at the time of writing this guide, is Apache Maven 3.8.2. By the time you are reading this guide, chances are that another version will be the latest release. So, check<a href=\"https:\/\/maven.apache.org\/download.cgi\"> Apache Maven\u2019s download<\/a> page.<\/p>\n<p>To download the Archive file, run:<\/p>\n<pre><strong>$ wget https:\/\/downloads.apache.org\/maven\/maven-3\/3.8.2\/binaries\/apache-maven-3.8.2-bin.tar.gz<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"967\" height=\"241\" class=\"wp-image-9568\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-475.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-475.png 967w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-475-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-475-768x191.png 768w\" sizes=\"auto, (max-width: 967px) 100vw, 967px\" \/><\/strong><\/p>\n<p>Next, extract the archive to the <strong>\/opt<\/strong> directory.<\/p>\n<pre><strong>$ sudo tar -xvf apache-maven-3.8.2-bin.tar.gz -C \/opt<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"167\" class=\"wp-image-9569\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-476.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-476.png 794w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-476-300x63.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-476-768x162.png 768w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><\/strong><\/p>\n<p>Thereafter, create a symbolic link that points to the installation directory<\/p>\n<pre><strong>$ sudo ln -s \/opt\/apache-maven-3.8.2 \/opt\/maven<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"60\" class=\"wp-image-9570\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-477.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-477.png 750w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-477-300x24.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/strong><\/p>\n<h3><strong>Step 4: Configure environment variables<\/strong><\/h3>\n<p>The next course of action is to set up or configure environment variables. First, create the <strong>maven.sh<\/strong> shell script file.<\/p>\n<pre><strong>$ sudo vim \/etc\/profile.d\/maven.sh<\/strong><\/pre>\n<p>Paste these lines and save the file.<\/p>\n<pre><strong>export JAVA_HOME=\/usr\/lib\/jvm\/jre-openjdk<\/strong>\r\n\r\n<strong>export M2_HOME=\/opt\/maven<\/strong>\r\n\r\n<strong>export MAVEN_HOME=\/opt\/maven<\/strong>\r\n\r\n<strong>export PATH=${M2_HOME}\/bin:${PATH}<\/strong><\/pre>\n<p>Next, make the script executable.<\/p>\n<pre><strong>$ sudo chmod +x \/etc\/profile.d\/maven.sh<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"643\" height=\"73\" class=\"wp-image-9571\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-478.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-478.png 643w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-478-300x34.png 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/strong><\/p>\n<p>Then load the environment variables using the source command.<\/p>\n<pre><strong>$ source \/etc\/profile.d\/maven.sh<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"74\" class=\"wp-image-9572\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-479.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-479.png 616w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-479-300x36.png 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/strong><\/p>\n<h3><strong>Step 5: Verify installation<\/strong><\/h3>\n<p>At this point, the installation of Apache Maven is complete. As before, you can verify this using the command:<\/p>\n<pre><strong>$ mvn --version<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"137\" class=\"wp-image-9573\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-480.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-480.png 872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-480-300x47.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-480-768x121.png 768w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\" \/><\/strong><\/p>\n<p>This wraps up this guide on how to install Apache Maven on Rocky Linux. You can now visit the <a href=\"https:\/\/maven.apache.org\/guides\/index.html\">Documentation page<\/a> to learn how you can get started with managing Java projects with Apache Maven.<\/p>","protected":false},"excerpt":{"rendered":"<p>Written in Java and licensed under Apache License v2, Apache Maven is an open-source software project management and build tool that is tailored specifically for Java projects. In&hellip;<\/p>","protected":false},"author":1,"featured_media":9613,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[407,93],"class_list":["post-9562","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\/9562","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=9562"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9562\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/9613"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=9562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=9562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=9562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}