How to Install Apache Maven on Ubuntu 22.04

How to Install Apache Maven on Ubuntu 22.04

Apache Maven is a helpful tool that helps organize and build Java projects easily. It’s like a smart assistant for programmers working on Java projects, making sure everything is put together correctly and ready to use.

Ubuntu 22.04 apache maven; Through this tutorial, we will learn how to download, install and setup apache maven on linux ubuntu 22.04.

How to Install Apache Maven in Ubuntu 22.04

Steps to download, install and setup apache maven on Linux ubuntu 22.04 using command line or terminal:

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

Step 1 – Install OpenJDK

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

Then execute the following command into it 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.

Copy the link to the latest Binary tar.gz file.

For example: https://apache.osuosl.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz

Download the Apache Maven in the /tmp directory:

cd ~   # or cd /opt
wget https://apache.osuosl.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz

Once the download is finished, extract the archive in the /opt directory:

tar -xvzf apache-maven-3.8.4-bin.tar.gz

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

mv apache-maven-3.8.4 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 – Refresh Bash Environment

To apply the changes made to the .bashrc file, you need to reload the Bash environment. Run the following command:

source ~/.bashrc

Step 5 – Verify the installation

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

mvn -version

Conclusion

Congratulations! You’ve successfully installed Apache Maven on your Ubuntu 22.04 system. You can now use Maven to manage and build your Java projects.

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 *