Maven is a common build tool for Java projects. Here we look at how to install it on various systems.

Gentoo

Install Java, see HowTo: Install Java - Gentoo

Console - user@hostname ~ $

1
sudo emerge --ask --verbose dev-java/maven-bin

Run the following the make sure it’s working:

Console - user@hostname ~ $

1
mvn --version

Ubuntu

Install Java, see HowTo: Install Java - Debian / Ubuntu

Install maven:

Note When attempting to install, we may get a message E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?. If this happens, run sudo apt-get update and try again.

Console - user@hostname ~ $

1
sudo apt-get install maven

Run the following the make sure it’s working:

Console - user@hostname ~ $

1
mvn --version

Amazon Linux

Install Java, see HowTo: Install Java - Fedora / RedHat / CentOS / Amazon

Go to the Download Apache Maven page and get the link for the latest binary tar.gz. In this example the mirror is http://mirrors.ibiblio.org/apache/ and the version is 3.2.5:

Console - user@hostname ~ $

1
2
3
4
5
curl -O http://mirrors.ibiblio.org/apache/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
sudo tar xzf apache-maven-3.2.5-bin.tar.gz -C /usr/local
cd /usr/local
sudo ln -s apache-maven-3.2.5 maven
cd $HOME

Set the M2_HOME environment variable to /usr/local/maven and add ${M2_HOME}/bin to the PATH environment variable:

Console - user@hostname ~ $

1
2
3
4
5
cat <<'EOF'>> maven.sh
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}
EOF
sudo mv maven.sh /etc/profile.d/maven.sh
Note The M2_HOME environment variable is optional, but since the PATH environment variable needs to be updated, we are showing both. If you want, you can skip M2_HOME and set PATH=/usr/local/maven/bin:${PATH}

Either run bash or log out and back in again to actually set the environment variables.

Run the following the make sure it’s working:

Console - user@hostname ~ $

1
mvn --version

Mac OS X

Prior to Mac OS X 10.9, maven 3 came preinstalled. You can run the following to see if it is installed, and if so what the version is:

Console - user@hostname ~ $

1
mvn --version

Install Java, see HowTo: Install Java - Mac OS X

Go to the Download Apache Maven page and get the link for the latest binary tar.gz. In this example the mirror is http://mirrors.ibiblio.org/apache/ and the version is 3.2.5:

Console - user@hostname ~ $

1
2
3
4
5
curl -O http://mirrors.ibiblio.org/apache/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
sudo tar xzf apache-maven-3.2.5-bin.tar.gz -C /usr/local
cd /usr/local
sudo ln -s apache-maven-3.2.5 maven
cd $HOME

We need to set the M2_HOME environment variable to /usr/local/maven and we need to add ${M2_HOME}/bin to the PATH environment variable. See the HowTo: Set an Environment Variable in Mac OS X for setting environment variables in Mac OS X.

If you followed the setup in HowTo: Set an Environment Variable in Mac OS X - Terminal Only. You can add the following to your ~/.bashrc file:

~/.bashrc (Excerpt)

1
2
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}

Or if you want all users to have access you can do this:

Console - user@hostname ~ $

1
2
3
4
5
cat <<'EOF'>> maven.sh
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}
EOF
sudo mv maven.sh /etc/profile.d/maven.sh
Note The M2_HOME environment variable is optional, but since the PATH environment variable needs to be updated, we are showing both. If you want, you can skip M2_HOME and set PATH=/usr/local/maven/bin:${PATH}

Windows

Install Java, see HowTo: Install Java - Windows

Go to the Download Apache Maven page and get the link for the latest binary zip. In this example the version is 3.2.5 and would be named: apache-maven-3.2.5-bin.zip.

Decide where to install it, in this example we’ll unzip it in C:\Program Files\Apache Software Foundation, thus giving us C:\Program Files\Apache Software Foundation\apache-maven-3.2.5

We’ll need to set the environment variable M2_HOME to C:\Program Files\Apache Software Foundation\apache-maven-3.2.5. Also we need to add C:\Program Files\Apache Software Foundation\apache-maven-3.2.5\bin to the PATH environment variable. See HowTo: Set and Environment Variable in Windows on how to do that.

Note The M2_HOME environment variable is optional, but since the PATH environment variable needs to be updated, we are showing both.

Run the following in the command prompt or PowerShell to make sure it’s working:

Command Prompt - C:\>

1
mvn --version

References

Comments