How to install Maven on CentOS

Last updated on October 14, 2020 by Dan Nanni

Apache Maven is a project management software, managing building, reporting and documentation of a Java-based development project. In order to install and configure Apache Maven on CentOS, follow these steps.

First of all, you need to install Java development kit (JDK). Make sure to install JDK, not Java Runtime Environment (JRE).

Then go ahead and download the latest Maven binary from its official site. For example, for version 3.0.4:

$ wget http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz
$ sudo tar xzf apache-maven-3.0.4-bin.tar.gz -C /usr/local
$ cd /usr/local
$ sudo ln -s apache-maven-3.0.4 maven

Next, set up Maven path system-wide:

$ sudo vi /etc/profile.d/maven.sh
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}

Finally, log out and log in again to activate the above environment variables. To verify successful installation of Maven, check the version of Maven:

$ mvn -version

Use Maven Behind Proxy

Optionally, if you are using Maven behind a proxy, you must define the proxy as follows.

$ vi ~/.m2/settings.xml
<settings>
  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.host.com</host>
      <port>port_number</port>
      <username>proxy_user</username>
      <password>proxy_user_password</password>
      <nonProxyHosts>www.google.com|*.somesite.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean