Thursday, October 2, 2025
HomeGuest BlogsHow 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

RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7079 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS