How to Install Apache Maven on Ubuntu 22.04

How to Install Apache Maven on Ubuntu 22.04

Install apache maven on Linux ubuntu 22.04; Through this tutorial, we will learn how to install apache maven on linux ubuntu 22.04.

How to Install Apache Maven on Ubuntu 22.04

Use the following steps to install apache maven on Linux ubuntu 22.04:

  • Step 1 – Install OpenJDK
  • Step 2 – Downloading Apache Maven
  • Step 3 – Setup environment variables
  • Step 4 – Verify the installation

Step 1 – Install OpenJDK

First of all, Open the terminal application by pressing Ctrl+Alt+T.

Then execute the following command on command line to install openJDK on linux ubuntu system:

sudo apt update
sudo apt install default-jdk

Verify the installation by executing the following command on command line:

java -version

Step 2 – Downloading Apache Maven

visit the Maven download page to see if a newer version is available.

Download the Apache Maven in 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 finished, extract the archive in the /opt directory:

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

To have more control over Maven versions and updates, we will create a symbolic link maven that will point to the Maven installation directory:

sudo ln -s /opt/apache-maven-3.6.3 /opt/maven

Step 3 – Setup environment variables

set up the environment variables. So, open your text editor and create a new file named maven.sh in the /etc/profile.d/ directory.

sudo nano /etc/profile.d/maven.sh

Then add the following code into it:

export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Make the script executable with chmod :

sudo chmod +x /etc/profile.d/maven.sh

Finally, load the environment variables using the source command:

source /etc/profile.d/maven.sh

Step 4 – Verify the installation

Execute the following command on command line to verify maven installation:

mvn -version

Conclusion

Through this tutorial, We have shown you how to install Apache Maven on Ubuntu 20.04.

Recommended Linux Ubuntu Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *