Skip to content

Instantly share code, notes, and snippets.

@miroslavtamas
Created April 22, 2016 10:48
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save miroslavtamas/cdca97f2eafdd6c28b844434eaa3b631 to your computer and use it in GitHub Desktop.
Save miroslavtamas/cdca97f2eafdd6c28b844434eaa3b631 to your computer and use it in GitHub Desktop.
Install Apache Maven 3.3.9 on CentOS
#!/bin/sh
wget http://www.eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
tar xzf apache-maven-3.3.9-bin.tar.gz
mkdir /usr/local/maven
mv apache-maven-3.3.9/ /usr/local/maven/
alternatives --install /usr/bin/mvn mvn /usr/local/maven/apache-maven-3.3.9/bin/mvn 1
alternatives --config mvn
@viveknarang
Copy link

Awesome Script! Thanks

@nadalizadeh
Copy link

nadalizadeh commented Sep 30, 2017

Perfect, Except that for the alternative command I needed to uninstall original maven package using yum remove maven

@adveres
Copy link

adveres commented Dec 14, 2017

@nadalizadeh you must have had a previous installation of maven. Script worked fine for me as it's written. Although it wouldn't harm the gist having a yum remove -y maven in it.


As a side note I don't think alternatives --config mvn is necessary if this is the only mvn install, also the script above sets the priority to 1 in the install line. Reason I mention it is because I want this in a Dockerfile and I can't have alternatives --config mvn asking for user input.
You could instead say alternatives --auto mvn via this man page.

@rstatsinger
Copy link

Awesome! Thanks!

@chiragbparikh
Copy link

The line 7 seems in correct. You have already moved apache-maven-3.3.9 to /usr/local/maven.
Probably should be
alternatives --install /usr/bin/mvn mvn /usr/local/maven/bin/mvn 1

@raovenk0
Copy link

Awesome !

@DefteZ
Copy link

DefteZ commented Oct 26, 2021

EU mirror is not available anymore.
Now we should use something like https://www.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment