How to Install Apache Maven on Ubuntu 22.04


To install Apache Maven in ubuntu 22.04, Start the terminal window and install OpenJDK using sudo apt install default-jdk, and type sudo apt install maven -y to install Apache Maven, and after setting the environment variables for Apache Maven, and finally verify the apache maven installation using mvn --version command on the terminal window.

Here are some steps you follow to download, install, and set up Apache Maven on Linux Ubuntu 22.04 via the terminal:

Step 1 – Update System Packages

Press Ctrl+Alt+T on keyboard to start terminal windows, To update the system’s packages, you need to use the sudo apt update command on a terminal window:

sudo apt update

Step 2 – Install OpenJDK

Before installing Apache Maven, you need to install OpenJDK in Ubuntu system, Type sudo apt install default-jdk command on terminal window:

sudo apt install default-jdk

Once OpenJDK is installed, type java --version command on terminal windows to verify installation:

java -version

Step 3 – Install Apache Maven Ubuntu

To install Apache Maven on Ubuntu, simply open a terminal window and simply type the command sudo apt install maven -y into it, press enter, and it will install latest stable version of Apache Maven and its related libraries:

sudo apt install maven -y

Step 4 – Setup environment variables

To setup environment variables for Apache Maven, simply type sudo nano /etc/profile.d/ command on a terminal window to open the configuration file:

sudo nano /etc/profile.d/

Then add the following code in file:

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/

Finally, load the environment variables using the source command:

source /etc/profile.d/

Step 5 – Refresh Bash Environment

To apply the changes made to the .bashrc file, you need to reload the Bash environment by typing source ~/.bashrc command on terminal windows:

source ~/.bashrc

Step 6 – Verify the installation

To verify that Apache Maven is installed on your system, type the mvn --version command in a terminal window and press Enter:

mvn -version

Now you will see output like this on your terminal window:

Apache Maven 3.8.4 (ceceaa473008596f0aab50b32c541b9a6ba3983d)
Maven home: /opt/apache-maven-3.8.4

If ever you need to uninstall Apache Maven from the Ubuntu system, you just type the command sudo apt remove maven -y on the terminal window, press enter, This command will completely uninstall or remove Apache Maven and its associated directories, subdirectories, and contents from your system.


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


Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Jassweb, Rai Chak, Punjab, India. 143518