How to install Maven on CentOS

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

First of all, you need to install Java 1.6 JDK. Make sure to install Java JDK, not 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

Optionally, if you are using Maven behind a proxy, you must do the following.

$ 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>

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

10 thoughts on “How to install Maven on CentOS

      • Thanks for pointing it out. I should have clarified that scripts in /etc/profile.d/ are called when a new login shell gets started. So it would have been sufficient to log out and log back in to make the PATH environment variable properly updated. Post has been clarified on that.

  1. After this step:
    sudo vi /etc/profile.d/maven.sh
    i can't do anything. When I log in it says: M2_HOME, PATH command not found.
    And even when I call for example man or vim it Command not found.

    • Well, the existing link is not broken. You can always download the latest version of Maven from the official Apache website if you want. I added a link to the download page in the post.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *