简体   繁体   中英

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?

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!!!**

Build it from the source. https://maven.apache.org/download.cgi

Installing Maven


  1. Unpack the archive where you would like to store the binaries, eg:
Unix-based operating systems (Linux, Solaris and Mac OS X)
  tar zxvf apache-maven-3.x.y.tar.gz
Windows
  unzip apache-maven-3.x.y.zip
  1. A directory called "apache-maven-3.xy" will be created.

  2. Add the bin directory to your PATH, eg:

Unix-based operating systems (Linux, Solaris and Mac OS X)
  export PATH=/usr/local/apache-maven-3.x.y/bin:$PATH
Windows
  set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
  1. Make sure JAVA_HOME is set to the location of your JDK

  2. Run "mvn --version" to verify that it is correctly installed.

For complete documentation, see https://maven.apache.org/download.html#Installation

JAVA_HOME=/usr/ib/jvm/java-11-openjdk-amd64 should be JAVA_HOME=/usr/ lib /jvm/java-11-openjdk-amd64 which is the default Java 11 (OpenJDK) directory.

Following command helped me.

Remove current version:

sudo apt-get purge maven

Download the latest version:

wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

Installation:

sudo cp -r apache-maven-3.8.6 /opt
export PATH=/opt/apache-maven-3.8.6/bin:$PATH

Note : Make sure Java should install before following the above steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM