How to install Maven on CentOS

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 JRE.

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

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

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.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of 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.

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/
    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 *