{"id":3292,"date":"2018-11-12T03:51:06","date_gmt":"2018-11-12T03:51:06","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=3292"},"modified":"2018-11-17T13:37:11","modified_gmt":"2018-11-17T13:37:11","slug":"how-to-install-apache-maven-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/12\/how-to-install-apache-maven-on-centos-7\/","title":{"rendered":"How to install Apache Maven on CentOS 7"},"content":{"rendered":"<p>Apache Maven is a free and open source project management and comprehension tool used primarily for Java projects. Maven uses a Project Object Model (POM) which is essentially a XML file containing information about the project, configuration details, the project\u2019s dependencies, and so on.<\/p>\n<p>In this tutorial we will show you two different ways to install Apache Maven on CentOS 7.<\/p>\n<p>The official CentOS repositories contains Maven packages that can be installed with the yum package manager. This is the easiest way to install Maven on CentOS, however the version included in the repositories may lag behind the latest version of Maven.<\/p>\n<p>To install the latest version of Maven follow the instructions provided in second part of this article where we will be downloading Maven from their official website.<\/p>\n<p>Choose the installation method that is most appropriate for your setup and environment.<\/p>\n<h2>Prerequisites<\/h2>\n<p>The user you are logging in as must have <a href=\"\/post\/create-a-sudo-user-on-centos\/\">sudo privileges<\/a> to be able to install packages.<\/p>\n<h2>Installing Apache Maven on CentOS with Yum<\/h2>\n<p>Installing Maven on CentOS 7 using yum is a simple, straightforward process.<\/p>\n<ol>\n<li>Install Maven by typing the following command in your terminal:<\/li>\n<li>Verify the installation by typing the mvn -version command:\n<p>The output should look something like this:<\/p>\n<p>Apache Maven 3.0.5 (Red Hat 3.0.5-17)<br \/>\nMaven home: \/usr\/share\/maven<br \/>\nJava version: 1.8.0_191, vendor: Oracle Corporation<br \/>\nJava home: \/usr\/lib\/jvm\/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64\/jre<br \/>\nDefault locale: en_US, platform encoding: UTF-8<br \/>\nOS name: &#8220;linux&#8221;, version: &#8220;3.10.0-862.3.2.el7.x86_64&#8221;, arch: &#8220;amd64&#8221;, family: &#8220;unix&#8221;<\/li>\n<\/ol>\n<p>That\u2019s it. Maven is now installed on your CentOS system and you can start using it.<\/p>\n<h2>Install the Latest Release of Apache Maven<\/h2>\n<p>The following sections provide a step by step instructions about how to install the latest Apache Maven version on CentOS 7. We\u2019ll be downloading the latest release of Apache Maven from their official website.<\/p>\n<h3>1. Install OpenJDK<\/h3>\n<p>Maven 3.3+ require JDK 1.7 or above to be installed. We\u2019ll install OpenJDK, which is the default Java development and runtime in CentOS 7.<\/p>\n<p>Install the OpenJDK package by typing:<\/p>\n<p>Verify that Java was successfully installed by running the following command:<\/p>\n<p>The output should look something like this:<\/p>\n<p>openjdk version &#8220;1.8.0_191&#8221;<br \/>\nOpenJDK Runtime Environment (build 1.8.0_191-b12)<br \/>\nOpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)<\/p>\n<h3>2. Download Apache Maven<\/h3>\n<p>At the time of writing this article, the latest version of Apache Maven is 3.6.0. Before continuing with the next step you should check the <a href=\"https:\/\/maven.apache.org\/download.cgi\">Maven download page<\/a> to see if a newer version is available.<\/p>\n<p>Start by downloading the Apache Maven in the \/tmp directory using the following <a href=\"\/post\/wget-command-examples\/\">wget<\/a> command:<\/p>\n<p>wget https:\/\/www-us.apache.org\/dist\/maven\/maven-3\/3.6.0\/binaries\/apache-maven-3.6.0-bin.tar.gz -P \/tmp<\/p>\n<p>When the download is completed, <a href=\"\/post\/how-to-create-and-extract-archives-using-the-tar-command-in-linux\/\">extract the archive<\/a> in the \/opt directory:<\/p>\n<p>sudo tar xf \/tmp\/apache-maven-3.6.0.tar.gz -C \/opt<\/p>\n<p>To have more control over Maven versions and updates, we will create a symbolic link maven which will point to the Maven installation directory:<\/p>\n<p>sudo ln -s \/opt\/apache-maven-3.6.0 \/opt\/maven<\/p>\n<p>To upgrade your Maven installation, simply unpack the newer version and change the symlink to point to it.<\/p>\n<h3>3. Setup environment variables<\/h3>\n<p>Next, we\u2019ll need to setup the environment variables. Open your text editor and create a new file named mavenenv.sh inside of the \/etc\/profile.d\/ directory.<\/p>\n<p>sudo nano \/etc\/profile.d\/maven.sh<\/p>\n<p>Paste the following lines:<\/p>\n<p>\/etc\/profile.d\/maven.sh<\/p>\n<p>export JAVA_HOME=\/usr\/lib\/jvm\/jre-openjdk<br \/>\nexport M2_HOME=\/opt\/maven<br \/>\nexport MAVEN_HOME=\/opt\/maven<br \/>\nexport PATH=$\/bin:$<\/p>\n<p>Save and close the file. This script will be sourced at shell startup.<\/p>\n<p>Make the script executable by typing:<\/p>\n<p>sudo chmod +x \/etc\/profile.d\/maven.sh<\/p>\n<p>Load the environment variables by typing:<\/p>\n<p>source \/etc\/profile.d\/maven.sh<\/p>\n<h3>4. Verify the installation<\/h3>\n<p>To verify that Maven is installed, use the mvn -version command which will print the Maven version:<\/p>\n<p>You should see something like the following:<\/p>\n<p>Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)<br \/>\nMaven home: \/opt\/maven<br \/>\nJava version: 1.8.0_191, vendor: Oracle Corporation, runtime: \/usr\/lib\/jvm\/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64\/jre<br \/>\nDefault locale: en_US, platform encoding: UTF-8<br \/>\nOS name: &#8220;linux&#8221;, version: &#8220;3.10.0-862.3.2.el7.x86_64&#8221;, arch: &#8220;amd64&#8221;, family: &#8220;unix&#8221;<\/p>\n<p>That\u2019s it. The latest version of Maven is now installed on your CentOS system.<\/p>\n<h2>Conclusion<\/h2>\n<p>You have successfully installed Apache Maven on your CentOS 7. You can now visit the official <a href=\"https:\/\/maven.apache.org\/guides\/index.html\">Apache Maven Documentation<\/a> page and learn how to get started with Maven.<\/p>\n<p>If you hit a problem or have a feedback, leave a comment below.<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=262756\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache Maven is a free and open source project management and comprehension tool used primarily for Java projects. Maven uses a Project Object Model (POM) which is essentially a XML file containing information about the project, configuration details, the project\u2019s dependencies, and so on. In this tutorial we will show you two different ways to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/12\/how-to-install-apache-maven-on-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to install Apache Maven on CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3292","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=3292"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3292\/revisions"}],"predecessor-version":[{"id":3542,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3292\/revisions\/3542"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=3292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=3292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}