This article was first published in: https://www.itcoder.tech/posts/how-to-install-apache-maven-on-ubuntu-20-04/
Article Directory
Apache Maven is an open source project management tool, mainly used for Java projects. Maven uses a project object model (POM), which is a basic XML information that contains project information, configuration details, project dependencies, and so on.
In this guide, we will show two different ways to install Apache Maven on Ubuntu 20.04.
The official Ubuntu software source contains Maven packages, which can be installed through the apt
package management tool. This is the easiest way to install Maven on Ubuntu. In any case, the Maven version number in the software source will lag behind the latest Maven version number.
To install the latest version of Maven, follow the instructions provided in the second part of the article and download the binary compressed package from the official Maven website.
Choose the installation method that best suits your installation configuration and environment.
These instructions assume that you have logged into the system as root or another sudo user.
apt
to install Apache Maven on Ubuntu 20.04Installing Maven on Ubuntu using apt
is very simple and straightforward.
Upgrade the package index and enter the following command to install Maven:
sudo apt update
sudo apt install maven
To verify that the installation was successful, run mvn -version
:
mvn -version
The output looks like this:
Apache Maven 3.6.3
Maven home:/usr/share/maven
Java version:11.0.7, vendor: Ubuntu, runtime:/usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name:"linux", version:"5.4.0-26-generic", arch:"amd64", family:"unix"
that's it. Maven is now installed on your system, and you are already using it.
In this chapter, we will provide step-by-step instructions on downloading and installing the latest version of Apache Maven on Ubuntu 20.04.
Maven 3.3+ install JDK 1.7 or above.
Enter the following command to install OpenJDK 11
:
sudo apt update
sudo apt install default-jdk
Run the following command to verify the installation process:
java -version
The output looks like this:
openjdk version "11.0.7"2020-04-14
OpenJDK Runtime Environment(build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM(build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
At the time of writing, the latest version of Apache Maven is 3.6.3
. After continuing to the next step, browse Maven download page to see if there is a newer version available.
Download Apache Maven to the /tmp
directory:
wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
Once the download is complete, unzip the compressed package to the /opt
directory:
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
To have better control over Maven versions and updates, we will create a symbolic link to point to the Maven installation directory:
sudo ln -s /opt/apache-maven-3.6.3/opt/maven
When a new version is released, you can upgrade your Maven in the following way: unzip the new version and modify the symbolic link to point to it.
Next, we will set environment variables. To do this, open your text editor and create a new file in the /etc/profile.d/
directory and name it mavenenv.sh
.
sudo nano /etc/profile.d/maven.sh
Paste the code below:
export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Save and close the file. The script will take effect when the shell is started.
To make the script executable, use chmod
:
sudo chmod +x /etc/profile.d/maven.sh
Finally, use the source
command to reload the environment variables.
source /etc/profile.d/maven.sh
To verify whether Maven is installed successfully, use the mvn -version
command, it will print the Maven version:
mvn -version
You should see a message similar to the following:
Maven home:/opt/maven
Java version:11.0.7, vendor: Ubuntu, runtime:/usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name:"linux", version:"5.4.0-26-generic", arch:"amd64", family:"unix"
that's it. The latest version of Maven has been successfully installed on your Ubuntu system.
We have shown you how to install Apache Maven on Ubuntu 20.04. You can now browse the official Apache Maven Documentation Page and learn how to get started with Maven.
If you have any questions, please contact us in the following ways:
WeChat:
WeChat group: add the above WeChat, remark the WeChat group
QQ: 3217680847
QQ Group: 82695646
Original: https://linuxize.com/post/how-to-install-apache-maven-on-ubuntu-20-04/
Copyright notice: This work uses Creative Commons attribution-Share 4 in the same way.0 International license agreement for licensing.
Recommended Posts