Installing Maven 3 on Ubuntu 10.04 LTS Server

Installing Maven 3 on Ubuntu 10.04 LTS Server.
In preparing to upgrade a customer’s software recently I discovered there were issues with Maven version 2, so I also had to upgrade to Maven version 3.
Not a whole of information available about configuration, here’s what worked for me.

Download Maven 3.
$ cd /home/myusername
$ wget http://ftp.heanet.ie/mirrors/www.apache.org/dist//maven/binaries/apache-maven-3.0.2-bin.tar.gz
$ tar -xzvf apache-maven-3.0.2-bin.tar.gz …. unpacks Maven
$ sudo mkdir /usr/local/apache-maven … creates a maven sub-folder in the usr/local/ folder
$ sudo cp -R apache-maven-3.0.2 /usr/local/apache-maven/ …. copies extraced Maven files to the new sub-folder.

Add the Maven 3 PATH variables to the environment file.
$ sudo nano /etc/environment … to edit the environment file.

Two changes required:
Firstly add the following lines.
JAVA_HOME=”/usr/lib/jvm/java-6-openjdk”
M2_HOME=”/usr/local/apache-maven/apache-maven-3.0.2″
MAVEN_HOME=”/usr/local/apache-maven/apache-maven-3.0.2″
M2=”/usr/local/apache-maven/apache-maven-3.0.2/bin”

Secondly change the top line for PATH. It should look like this:
PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”
Modify it to look like this:
PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/apache-maven/apache-maven-3.0.2/bin”

Testing the Installation:
Logout:
$ logout

Log back in:

Run the Maven version checker:
$ mvn –version
It should return something like

Note – Do not proceed until a Maven 3 version and Java Version are being returned.

Create the Maven home folder (Did this anyway, not sure if necessary but hasn’t caused any issues).
$ mkdir /home/myusername/.m2
$ chown myserver.myusername -R /home/myusername/.m2 … grants the myusername user full rights to the Maven folder

About these ads

32 Comments »

  1. Paranormal said

    it worked perfect thank you very much

  2. YOMorales said

    Hi:

    Did exactly this (in Ubuntu) and got an error at the end. Something about: “Exception in thread “main” java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher”.

    After googling a bit, I found out something about changing the number 2 for 3 in the path variables, like:

    M3_HOME
    M3

    .. and everything is now working perfect.

  3. lukieb said

    The 3.0.2 Maven version I downloaded above seems to be no longer available from my ftp mirror. Try this instead $wget http://ftp.heanet.ie/mirrors/www.apache.org/dist//maven/binaries/apache-maven-3.0.3-bin.tar.gz

    lukieb

  4. Jigs said

    After following those steps I am getting only this message.

    The program ‘mvn’ is currently not installed. You can install it by typing:
    sudo apt-get install maven2

    my $PATH,$M2 and $M2_HOME all variables are good.

    NOT sure why am I getting this.

    • Cris said

      Have the same thing…
      Any idea how can this be resolved…?
      Thanks

      • venktesh said

        Same for me even. I don’t think anywhere we did anything to install it.. Plz help..

      • Andrey said

        Cris,
        Did you install jdk? Can you please confirm by running
        $java -version
        I just installed mvn following the instructions, all works fine. Make sure there are no typos.

  5. Ajit Wadekar said

    Hi ,
    we need to set M3_HOME instead of M2_HOME if we set M2_HOME it gives error of class loader

  6. bakeha said

    Yep when I use M3 instead of M2 it works like a charm. Cheers

  7. Gagan said

    refer this link : http://www.discursive.com/blog/4636

  8. Did exactly this (in Ubuntu) and got an error at the end. Something about: “Exception in thread “main” java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher”.
    +1

  9. Sebastiaan said

    fix the text,.. need to say M3 in environment.

  10. marcosl_sl said

    After following those steps I am getting:
    marcos@linux1:/usr/local/apache-maven-3.0.3$ mvn -version
    Apache Maven 2.2.1 (rdebian-1)
    Java version: 1.6.0_20
    Java home: /usr/lib/jvm/java-6-openjdk/jre
    Default locale: es_AR, platform encoding: UTF-8
    OS name: “linux” version: “2.6.31-23-generic” arch: “amd64″ Family: “unix”

    and the /etc/enviroment has:
    PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/apache-maven-3.0.3/bin”
    JAVA_HOME=”/usr/lib/jvm/java-6-openjdk”
    M3_HOME=”/usr/local/apache-maven-3.0.3″
    MAVEN_HOME=”/usr/local/apache-maven-3.0.3″
    M3=”/usr/local/apache-maven-3.0.3/bin”

    I can’t install maven 3

  11. marcosl_sl said

    uninstall maven2 and resolve the problem

  12. [...] instructions below are based on Installing Maven 3 on Ubuntu 10.04 LTS Server from Luke Bourke. I am installing Maven 3.0.3 on Ubuntu 11.04 LTS Server with Oracle Java [...]

  13. To work I’ve not to add the java_home, but instead type this command in terminal: export JAVA_HOME=”/usr/lib/jvm/jdk1.7.0″.

    Hope that helps someone ;)

  14. after modifying the /etc/environment file, I must restart my ubuntu and maven 3 got succesfully installed.
    the command mvn -version returns this message:
    Apache Maven 3.0.3 (r1075438; 2011-03-01 00:31:09+0700)
    Maven home: /usr/local/apache-maven/apache-maven-3.0.3
    Java version: 1.7.0, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/jdk1.7.0/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: “linux”, version: “2.6.38-11-generic”, arch: “i386″, family: “unix”

    nice tutorial. thank you.

  15. asd said

    use the command
    source /etc/environment

    to get the path updates without the restart of ubuntu

  16. chrisspen said

    Your setup didn’t work for me using JAVA_HOME=”/usr/lib/jvm/java-6-openjdk”, which gave me the error:

    Error: JAVA_HOME is not defined correctly.
    We cannot execute ”/usr/lib/jvm/java-6-openjdk”/bin/java

    However, when I replaced this with JAVA_HOME=”/usr/lib/jvm/default-java” everything worked correctly.

  17. Vytautas said

    Check if quotation marks were copied correctly. ″ != “

  18. Rini said

    Thank you sooo much

  19. Jeff said

    Thanks this helped a lot.

  20. Here’s what I did on my Ubuntu 10.04 machine to convert my user’s environment from maven2 to maven3:

    #> cd /tmp
    #> wget http://ftp.heanet.ie/mirrors/www.apache.org/dist//maven/binaries/apache-maven-3.0.3-bin.tar.gz
    #> cd /usr/local
    #> sudo tar xvfz /tmp/apache-maven-3.0.3-bin.tar.gz

    Then I stuck this at the bottom of my .bashrc to put the new maven path ahead of the existing maven path (I haven’t uninstalled Maven 2 at this point…just testing it out) and setup the environment variables to be maven 3 instead of 2.

    # Switching from maven2 to maven3
    export M3_HOME=”/usr/local/apache-maven-3.0.3″
    export MAVEN_HOME=”/usr/local/apache-maven-3.0.3″
    export M3=”/usr/local/apache-maven-3.0.3/bin”
    export PATH=/usr/local/apache-maven-3.0.3/bin:$PATH
    unset M2_HOME

    Checked that maven was totally switched over:

    tvaughan:~ $ mvn –version
    Apache Maven 3.0.3 (r1075438; 2011-02-28 12:31:09-0500)
    Maven home: /usr/local/apache-maven-3.0.3
    Java version: 1.6.0_26, vendor: Sun Microsystems Inc.
    Java home: /usr/lib/jvm/java-6-sun-1.6.0.26/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: “linux”, version: “2.6.35-31-generic”, arch: “amd64″, family: “unix”

  21. [...] instructions below are based on Installing Maven 3 on Ubuntu 10.04 LTS Server from Luke Bourke. I am installing Maven 3.0.3 on Ubuntu 11.04 LTS Server with Oracle Java [...]

  22. Kanth Raj said

    the url no more exist and the steps are perfect to get installed thank you.

  23. manwann said

    Hi, i was working with maven 2 and all fine, but i comitted a project that needs maven 3, so i am interested in installing two instances of maven with ubuntu (v2 and v3).

    i am worry because i don’t know if will be any conflict between two versions.

    any help would be appreciated

  24. Kai Kunstmann said

    it appears that /usr/bin/mvn is a hardlink with /usr/share/maven2/bin/mvn on my system. I had to unlink it first and made some adjustments to get both maven 2 and 3. note, that I did not set any path variables.

    $ unlink /usr/share/maven2/bin/mvn ; mv /usr/bin/mvn /usr/share/maven2/bin/mvn
    $ unlink /usr/share/maven2/bin/mvnDebug; mv /usr/bin/mvnDebug /usr/share/maven2/bin/mvnDebug

    $ tar xzf apache-maven-3.0.4.tar.gz ; mv apache-maven-3.0.4

    $ update-alternatives –install /usr/bin/mvn mvn /usr/share/maven2/bin/mvn 2
    $ update-alternatives –install /usr/bin/mvnDebug mvnDebug /usr/share/maven2/bin/mvnDebug 2

    /usr/share/maven3
    $ update-alternatives –install /usr/bin/mvn mvn /usr/share/maven3/bin/mvn 3
    $ update-alternatives –install /usr/bin/mvnDebug mvnDebug /usr/share/maven3/bin/mvnDebug 3

    switch between mvn versions (and mvnDebug respectively):

    $ update-alternatives –config mvn
    $ update-alternatives –config mvnDebug

  25. John G said

    Thank you. I was able to install just fine even when I updated the version number to 3.0.4. Just replace 3.0.2 -> 3.0.4 after downloading the latest version.

  26. [...] [1] http://maven.apache.org/ [2] http://maven.apache.org/download.html [3] http://lukieb.wordpress.com/2011/02/15/installing-maven-3-on-ubuntu-10-04-lts-server/ [...]

  27. [...] instructions below are based on Installing Maven 3 on Ubuntu 10.04 LTS Server from Luke Bourke. I am installing Maven 3.0.3 on Ubuntu 11.04 LTS Server with Oracle Java [...]

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: