{"id":3180,"date":"2018-03-21T17:38:01","date_gmt":"2018-03-21T14:38:01","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/centos-apache-maven\/"},"modified":"2018-03-21T17:38:01","modified_gmt":"2018-03-21T14:38:01","slug":"how-to-install-apache-maven-on-centos-7","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/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 software project management tool based on the POM (Project, Object, Model) concept. Maven is a build automation tool used primarily for Java-based projects, but can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. It not only describes how software builds but also\u00a0its dependencies.<\/p>\n<p>In this tutorial, we will show you step-by-step how to install and configure Apache Maven on a CentOS 7 system.<\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<ul>\n<li>CentOS 7 Server<\/li>\n<li>Root privileges<\/li>\n<\/ul>\n<h2 id=\"what-we-will-do\">What we will do<\/h2>\n<ol>\n<li>Install Java OpenJDK on CentOS 7<\/li>\n<li>Download Apache Maven Binary Files<\/li>\n<li>Configure Apache Maven Environment<\/li>\n<li>Testing<\/li>\n<\/ol>\n<h2 id=\"step-install-java-openjdk-on-centos-\">Step 1 &#8211; Install Java OpenJDK on CentOS 7<\/h2>\n<p>The first thing we will do here is to\u00a0install Java on\u00a0the CentOS 7 server. Apache Maven requires JDK 1.7 or above &#8211; we will be using Java 8 that can be installed from the CentOS repository.<\/p>\n<p>Install Java 8 on CentOS 7 using the yum command.<\/p>\n<p class=\"command\">sudo yum install -y java-1.8.0-openjdk-devel<\/p>\n<p>After\u00a0the installation is complete, check the installed java version.<\/p>\n<p class=\"command\">java -version<\/p>\n<p>And you will get the result as below.<\/p>\n<p><a class=\"fancybox\" id=\"img-1\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_centos_7\/big\/1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-apache-maven-on-centos-7.png\" alt=\"Install Java OpenJDK on CentOS 7\" width=\"500\" height=\"152\" title=\"\"><\/a><\/p>\n<p>Java OpenJDK 8 has been installed on CentOS 7.<\/p>\n<h2 id=\"step-download-apache-maven\">Step 2 &#8211; Download Apache Maven<\/h2>\n<p>In this step, we will download the apache maven binary code using the wget command. And we will be using the &#8216;\/usr\/local\/src&#8217; directory as a maven home directory.<\/p>\n<p>Go to the &#8216;\/usr\/local\/src&#8217; directory and download the Apache Maven Binary code.<\/p>\n<p class=\"command\">cd \/usr\/local\/src<br \/>wget http:\/\/www-us.apache.org\/dist\/maven\/maven-3\/3.5.2\/binaries\/apache-maven-3.5.2-bin.tar.gz<\/p>\n<p>Extract the maven.tar.gz file, and then delete the\u00a0compressed file.<\/p>\n<p class=\"command\">tar -xf apache-maven-3.5.2-bin.tar.gz<br \/>rm -f apache-maven-3.5.2-bin.tar.gz<\/p>\n<p>And you will get a new directory apache-maven-version &#8211; rename the directory.<\/p>\n<p class=\"command\">mv apache-maven-3.5.2\/ apache-maven\/<\/p>\n<p>Apache Maven is now downloaded in\u00a0the &#8216;\/usr\/local\/src\/apache-maven&#8217; directory.<\/p>\n<p><a class=\"fancybox\" id=\"img-3\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_centos_7\/big\/3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-apache-maven-on-centos-7-1.png\" alt=\"Download Apache Maven\" width=\"500\" height=\"134\" title=\"\"><\/a><\/p>\n<h2 id=\"step-configure-apache-maven-environment\">Step 3 &#8211; Configure Apache Maven Environment<\/h2>\n<p>In this step, we will configure the environment for Apache Maven. We will define some environment variables that are needed by Apache Maven.<\/p>\n<p>Go to the &#8216;\/etc\/profile.d&#8217; directory and create a new configuration file &#8216;maven.sh&#8217;.<\/p>\n<p class=\"command\">cd \/etc\/profile.d\/<br \/>vim maven.sh<\/p>\n<p>Paste the following configuration there.<\/p>\n<pre class=\"system\"># Apache Maven Environment Variables<br\/># MAVEN_HOME for Maven 1 - M2_HOME for Maven 2<br\/>export M2_HOME=\/usr\/local\/src\/apache-maven<br\/>export PATH=${M2_HOME}\/bin:${PATH}<\/pre>\n<p>Save and exit.<\/p>\n<p>Now make the &#8216;maven.sh&#8217; script executable and then apply the configuration by running the &#8216;source&#8217; command.<\/p>\n<p class=\"command\">chmod +x maven.sh<br \/>source \/etc\/profile.d\/maven.sh<\/p>\n<p>The Apache Maven environment configuration has been completed.<\/p>\n<p><a class=\"fancybox\" id=\"img-2\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_centos_7\/big\/2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-apache-maven-on-centos-7-2.png\" alt=\"Configure Apache Maven Environment\" width=\"500\" height=\"141\" title=\"\"><\/a><\/p>\n<h2 id=\"step-testing\">Step 4 &#8211; Testing<\/h2>\n<p>To verify our Apache Maven installation, you\u00a0can run the maven command below.<\/p>\n<p class=\"command\">mvn &#8211;version<\/p>\n<p>And you should\u00a0get a result similar to the following:\u00a0<\/p>\n<p><a class=\"fancybox\" id=\"img-4\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_maven_on_centos_7\/big\/4.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-apache-maven-on-centos-7-3.png\" alt=\"Test apache maven\" width=\"500\" height=\"147\" title=\"\"><\/a><\/p>\n<p>Apache Maven 3.2 installation has been completed. It&#8217;s running under Linux CentOS 7 64bit, with Java 1.8 installed, and the Maven Home directory is &#8216;\/usr\/local\/src\/apache-maven&#8217;.<\/p>\n<h2 id=\"reference\">Reference<\/h2>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Apache Maven is a software project management tool based on the POM (Project, Object, Model) concept. Maven is a build automation tool used primarily for Java-based projects, but can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. It not only describes how software builds but also\u00a0its dependencies. &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3180","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3180"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3180\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}