Apache Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation. Maven Apache simplifies the build process like ANT but it is too much advanced than ANT.
In this tutorial we will show you two different ways to install latest version of Apache Maven on Ubuntu 20.04 LTS Using the apt
package manager or by a source from the Maven official website.
Prerequisites
sudo
privileges in order to install the Apache Maven.– Java Development Kit (JDK) is required to install Apache Maven. Use the following tutorial to Install Java : How to Install Java on Ubuntu 20.04
Method 1./ Installing Apache Maven using APT
– Use the below commands to update the repository packages and install the Apache Maven:
$ sudo apt update $ sudo apt install maven
– Run the mvn -version
command too verify if Apache Maven is successfully installed:
$ mvn -version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.2, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: ISO-8859-1
OS name: "linux", version: "5.4.0-33-generic", arch: "amd64", family: "unix"
Method 2./ Installing Apache Maven From Source
1. Download Apache Maven
– First, go to the official Apache Maven download page and use the wget
command to download the latest version of Apache Maven.
$ VERSION=3.6.0 $ wget https://www-us.apache.org/dist/maven/maven-3/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz -P /tmp
– Let’s extract the archive in the /opt
directory like below:
$ sudo tar -xzvf /tmp/apache-maven-${VERSION}-bin.tar.gz -C /opt
– Now, create a symbolic link maven
which will point to the Maven installation directory in our example is apache-maven-3.6.0
$ sudo ln -s /opt/apache-maven-${VERSION} /opt/maven
2. Setup environment variables
– Next, we’ll need to setup the environment variables. Open your text editor and create a new file named maven.sh
inside of the /etc/profile.d/
directory.
$ sudo vi /etc/profile.d/maven.sh export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export M2_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
– Finally, load the new environment variables by typing:
$ source /etc/profile.d/maven.sh
3. Verify the installation
– So, to verify that Maven is successfully installed, use the mvn -version
command which will print the Maven version:
$ mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /opt/maven
Java version: 10.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: ISO-8859-1
OS name: "linux", version: "5.4.0-33-generic", arch: "amd64", family: "unix"
Conclusion
You have successfully installed Apache Maven on your Ubuntu 20.04 LTS server. You might want to check the following guides:
- How to Install and use PIP on Ubuntu 20.04 LTS
- Learn How to Install Docker Compose on Ubuntu 20.04
- How To Install Node.js and npm on Ubuntu 20.04
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!