http://dev-maziarz.blogspot.nl/2012/09/ubuntu-1204-installing-both-maven3-and.html
Maven and /etc/alternatives
Ubuntu 12.04 comes with maven 3.0.4 as a default - that's great, but not for those who still needs maven 2.x. Unfortunately maven2 package can be installed can be installed only as the maven3 replacement - for those needed both, that sounds rather poor solution. Luckly there is /etc/alternatives mechanism that is perfect in such a case. It basically allows us having both with relativly easy way. But in that case alternatives does not work out of the box. The only way to handle this is installing maven2 binaries manually and register it as an alternative for
mvn
command.How to do this - step by step solution:
- Lets start with installing maven3 (3.0.4-2)
$ sudo apt-get install maven
- Once done we look at recently installed mvn using
update-alternatives
command.$ update-alternatives --list mvn /usr/share/maven/bin/mvn
$ update-alternatives --display mvn mvn - auto mode link currently points to /usr/share/maven/bin/mvn /usr/share/maven/bin/mvn - priority 150 slave mvn.1.gz: /usr/share/maven/man/mvn.1.gz slave mvnDebug: /usr/share/maven/bin/mvnDebug slave mvnDebug.1.gz: /usr/share/maven/man/mvnDebug.1.gz Current 'best' version is '/usr/share/maven/bin/mvn'.
Optionally fix the mvnDebug link into /usr/bin/mvnDebugln -s /etc/alternatives/mvnDebug /usr/bin/mvnDebug
- Download maven 2 and extract it into /usr/share/maven2 folder.
- Add alternatives
# update-alternatives --install /usr/bin/mvn mvn /usr/share/maven2/bin/mvn 200 --slave /usr/bin/mvnDebug mvnDebug /usr/share/maven2/bin/mvnDebug
Priority 200 as a greater then 150 makes maven2 it the default (auto).
# cd /usr/share && wget http://archive.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz
# tar xzvf apache-maven-2.2.1-bin.tar.gz && mv apache-maven-2.2.1 maven2 && rm apache-maven-2.2.1-bin.tar.gz