Learn the steps to install Apache Maven on Ubuntu 22.04 LTS Jammy JellyFish using the command terminal to manage Java-based projects.
Apache Maven is an open-source Java tool for the standardized creation and management of Java-based projects. As per the developers of Maven, it is intended to facilitate the daily development work by trying to automate as many steps as possible in the development cycle from the creation of a software project to compilation and testing to the distribution of the software. Based on the specified standards, only a few configuration settings have to be stored for most build management tasks to map the life cycle of a software project.
- Steps to install Apache Maven on Ubuntu 22.04 Linux
Steps to install Apache Maven on Ubuntu 22.04 Linux
The steps given here to configure Maven on Ubuntu 22.04 LTS can be used for other versions of it as well. Including Debian and Ubuntu-based OS such as Linux Mint, MX Linux, POP_OS, Elementary OS, and more…
Note: We have two ways to install Apache Maven – one is using the Standard APT repository and the other is by downloading its latest version manually to configure it.
#1st method using Ubuntu standard repository:
1. Run APT system update
Perform the system update to ensure you have the latest security updates and also this will rebuild the APT package manager’s cache.
sudo apt update
2. Install Apache Maven on Ubuntu 22.04
Well, we can install Maven using the default system repository of Ubuntu 22.04 and other versions of Ubuntu. However, you will not have the latest version of it instead well tested and stable one. For example, while doing this article the latest version of Maven was 3.8 while the one is available through the APT package manager and the standard repo of Ubuntu was 3.6.
sudo apt install maven
To check the version, after installation:
#2nd method by downloading the Latest Release of Apache Maven
3. Install OpenJDK on Ubuntu 22.04
If you are going for manual installation then we also have to configure Java. The default version of Java available in Ubuntu 22.04 is OpeJDK-11 which is compatible with Apache Maven’s latest version.
sudo apt install default-jdk
4. Download Apache Maven’s latest version
The user can directly visit the Apache Maven download page and get the latest version available there.
Or you can use the wget command:
Note: While doing this article the latest version was 3.8.5 and may differ in your case. Hence, first, visit the Maven download page, copy the link of the latest file and then use it with
wget to download using the command terminal.
Extract the file:
tar -xvf apache-maven-*-bin.tar.gz
Check the extracted file name:
Move it to
sudo mv apache-maven-3.8.5 /usr/share/maven
Note: Change apache-maven–3.8.5 in the above command with the name of your extracted folder.
5. Add the Maven folder to the System path
To use the maven command tool from anywhere in your terminal, add its folder path in your bash profile.
echo 'export PATH="$PATH:/usr/share/maven"' >> ~/.bashrc echo 'export PATH="$PATH:/usr/share/maven/bin"' >> ~/.bashrc
Reload Bash profile:
6. Check the MVN version
Now, to check the command line tool MVN of Apache Maven is working fine, print its version.
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: /usr/share/maven Java version: 11.0.15, vendor: Private Build, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en_IN, platform encoding: UTF-8 OS name: "linux", version: "5.17.5-051705-generic", arch: "amd64", family: "unix"
7. Create your first project
Well, those who are familiar with Maven would already know what to do for creating a project, whereas the new ones can check out the official Apache Maven website documentation to know more about it. Nevertheless, just to give an idea of how to start with this tool, here are the commands:
Create a project
Paste the given commanding your terminal. You replace the group ID, artifact ID, and other values as per your choice.
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
Switch to your create app project directory, here it is as per the above command- myapp
To test the newly compiled Jar files:
java -cp target/myapp-1.0-SNAPSHOT.jar com.mycompany.app.App
To create a site using POM.XML, run the given command inside your app directory:
Once done, run
8. Uninstall or Remove Apache Maven
In case you don’t want Maven on your system anymore, then as per the method, you have used to install it on Ubuntu 22.04, select one of the given ones to remove the same.
#1st method: For those who have used APT package manager:
sudo apt remove maven*
#2nd Method: Those who manually installed it:
sudo rm /usr/share/maven
To remove Java as well:
sudo apt autoremove default-jdk --purge