-
Notifications
You must be signed in to change notification settings - Fork 0
Maven Installation: Linux
Maven v3 is already in the repositories (for Ubuntu at least). I think the recent versions of Ubuntu ship with maven under the 'maven' package name and so an
apt-get install maven
should just work (no need for a PPA or changing the sources file). I think it's also worth perhaps avoiding mentioning maven2 and ensuring everyone is using the latest version to prevent any issues cropping up because some people used the wrong version.
It might also be worth mentioning that the apt-get method only works with distros that actually use that packaging system (maybe different sections for popular distros - debian, ubuntu etc).
Believe it or not, you can install maven with apt-get! In this tutorial we'll be installing maven2, but of course there'll be instructions on how to get setup with maven3 as well.
Let's get to it, first update your sources, just in case:
sudo apt-get update
Once thats done, install maven2:
sudo apt-get install -y maven2
If everything has gone well, you should be able to do:
mvn --version
Apache Maven 2.2.1 (rdebian-4)
Java version: 1.7.0_55
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux" version: "2.6.32-5-amd64" arch: "amd64" Family: "unix"
If you get a response similar to mine you should be good to go!
Unless you've manually updated your sources or added a ppa to your sources.list, I doubt you won't get an error when typing in
sudo apt-get install -y maven3
If you don't, well then you can skip this next step and head straight for step 3.
Let's get started on installing maven3. In order to do this you'll most likely have to add a few new lines to your sources.list file. I prefer using nano
for all my editing needs, but feel free to use whatever you prefer as well. For the sake of the tutorial though It'd be best to use the same editor as myself though, so no confusion arises.
So, step 1, add the sources to your sources.list:
nano /etc/apt/sources.list
And add in these lines:
deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main
deb-src http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main
Now exit out of nano by holding Ctrl-X.
Step 2, update sources and install maven3:
sudo apt-get update
sudo apt-get install -y maven3
Good! Now all that's left is to add a symbolic link for maven, so lets do that, step 3:
ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn
Alright, that's all there is to it! Check your current maven installation is working by doing
mvn --version
If your returned version is maven 3.x.x you've successfully installed maven3!
Now, if you feel like doing it the hard way (Not really), here's how you would install it manually:
Step 1, download the latest version of maven from Apache Maven, or use this command to download it to your current directory: (Note, if you did this make sure to remember what directory you've saved it to!)
wget 'http://tweedo.com/mirror/apache/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz' -O maven3.2.1-bin.tar.gz
Good, once that's done continue to unpack the downloaded archive to a directory of your choice, in this case I'll be putting it into
/usr/share/maven3
To do that, execute these commands while in the folder you originally saved that maven archive to:
sudo mkdir /usr/share/maven3/ && sudo tar -xzf maven3.2.1-bin.tar.gz -C /usr/share/maven3
Once that steps been completed go on to adding a symbolic link for maven:
ln -s /usr/share/maven3/apache-maven-3.2.1/bin/mvn /usr/bin/mvn
If everything until now's gone well you should be able to execute mvn --version
without any errors.
If everything working, then congratulations! You've successfully installed maven on linux!
Visit the site at tenjava.com
If you have any questions (about the contest, git, Maven etc), please don't hesitate to send us a tweet @tenjava or ask in our IRC channel.