mavenubuntu

Install latest maven package in Ubuntu via apt package manager or other ways


I am trying to install maven in linux machine using the following command:

sudo apt install maven

But this command installs the maven version 3.6.0, whereas the latest version for maven in the apache maven web-site is 3.8.1. Any suggestions on how to install maven 3.8.1 via apt install command or any else ways?


Solution

  • This is a small guide to install maven on ubuntu 20.04 LTS. Jul 28, 2021

    1. Download maven from https://maven.apache.org/download.cgi click the link apache-maven-3.8.1-bin.tar.gz.

    2. Extract the files in your downloads folder.

      cd Downloads

      sudo tar xzvf apache-maven-3.8.1-bin.tar.gz -C/opt/

    3. In a terminal window enter the following.

      nano .profile

    Edit the file and add the following text at the bottom of the page.

    JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    
    export JAVA_HOME
    
    MAVEN_HOME=/opt/apache-maven-3.8.1
    
    export MAVEN_HOME
    
    PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
    
    export PATH 
    

    Now press ctrl + O to save the file, and ctrl + X to close the file.

    1. Back in the terminal run the script with.

      . .profile

    Check the version of java and maven with the commands.

    `java --version`
    
    `mvn --version` 
    

    Now you should see the proper version of Maven installed.

    If you open a new terminal window and the installation seems ineffective: LOGOUT AND LOGIN!!!**