Apache Maven Installation

*This article provides step by step tutorial of Apache Maven installation on linux.


Apache Maven is Software Project Management and Configuration tool. Through it's bride acceptance in the java-developer community it introduces some kind of unification and standardisation in a structure of java Software projects. Long story short, every software project produces some artifacts (e.g .jar files). These are deployed, archived, copied, referenced and so on. Maven provides basic support for all kind of tasks like that. Therefore  if you're interested in professional software development, clean versioning, clear dependency management.


Version updated in 2018

#Download current release
cd /tmp  
wget http://artfiles.org/apache.org/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz  
#create target dir
sudo mkdir /usr/lib/apache-maven  
#Extract into it
tar -xzf apache-maven-3.5.3-bin.tar.gz -C /usr/lib/apache-maven/  

Now some environment variables need to be exposed.

export M2_HOME=/usr/lib/apache-maven/apache-maven-3.5.3  
export M2=$M2_HOME/bin  
export PATH=$M2:$PATH  

It is desirable to set these variable durable. You can add them to your bash .profile script by executing following lines at once.

echo '  
export M2HOME=/usr/lib/apache-maven/apache-maven-3.5.3  
export M2=$M2HOME/bin  
export PATH=$M2:$PATH ' >> ~/.bashrc  

Since we added maven to path, maven can be downloaded form every place in the system.

mvn --version  

Practically maven is now well preconfigured per default and suitable for most developers out of the box.

Additional Configuration

However personally i like to control some configuration. Basic configuration is done in settings.xml file. There are two locations where a settings.xml file may live:

  • The Maven install: $M2_HOME/conf/settings.xml
  • A user's install: ${user.home}/.m2/settings.xml

If both files exists, their contents gets merged, with the user-specific settings.xml being dominant.

Repository location

I prefer to set path of the repository location manually.



Here example of proxy configuration


Repository Mirror

It's possible to replace default repositories or some of them.Many organisation maintain their own repositories and you can link to them.

  <name>Maven Proxy</name>

Read more on mirroring details.