How to Install Apache Maven on Ubuntu 22.04

Configurare noua (How To)

Situatie

Maven is a free, open-source, popular build tool developed by the Apache Group. It is used to build, publish, and deploy several projects simultaneously for better performance. It is based on the concept of a project object model  and is used to manage projects written in C#, Ruby, Scala, and other languages.

Install Apache Maven From the APT Repository

By default, the Apache Maven package is included in the Ubuntu 22.04 default repository. You can install it by running the following command:

apt install maven -y

Once the Apache Maven is installed, you can verify its version using the following command:

mvn -version
Install Apache Maven from Source

The latest version of Apache Maven is not included in the Ubuntu 22.04 default repository by default. So it is a good idea to install the latest version of Apache Maven from the source.

Install Java JDK

Apache Maven is a Java-based application. So you will need to install the Java JDK to your server. You can install it with the following command:

apt install default-jdk -y

After the successful installation, verify the Java version using the following command:

java --version
Install Apache Maven

Next, download the latest version of Apache Maven using the following command:

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

Once the download is completed, extract the downloaded file to the /opt directory:

tar xzf apache-maven-3.8.5-bin.tar.gz -C /opt/

Next, navigate to the /opt directory and rename the extracted directory:

cd /opt/
mv apache-maven-3.8.5 maven

Next, you will need to create a maven.sh file to export the Apache Maven path.

nano /etc/profile.d/maven.sh

Add the following lines:

export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Save and close the file then activate the Maven environment with the following command:

source /etc/profile.d/maven.sh

Next, verify the Apache Maven version using the following command:

mvn -version

You can now choose your preferred way to install Apache Maven on Ubuntu 22.04

Solutie

Tip solutie

Permanent

Voteaza

(6 din 13 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?