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

Motivation

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

Installation

Maven versions 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 configured per default and suitable for most developers out of the box.

Additional Configuration

Personally I like to control some configuration. Basic configuration is done in settings.xml file. There are two locations where settings.xml file may live:

  • The Maven install dir: $M2_HOME/conf/settings.xml
  • A user’s home: ${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.

<localRepository>/yourpath/m2reporsitory/</localRepository>

Proxy

Proxy is loved child of every enterprize administrators. Here example of proxy configuration:

<proxies> 
 <proxy>
  <active>true</active>
  <protocol>http</protocol>
  <host>proxy.mycompany.com</host>
  <port>8080</port>
  <username>username</username>
  <password>password</password>
 </proxy>
</proxies>

Repository Mirror

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

<mirrors>
 <mirror>
  <id>org.mycompany</id>
  <name>Maven Proxy</name>
  <url>http://mycompany.org/maven_path</url>
  <mirrorOf>central</mirrorOf>
 </mirror>
</mirrors> 

Find more mirror settings options on apache maven site.

Hope you liked it.