## Tutorial ##
How To Install Maven on Ubuntu 22.04
Published on May 20 2023 · Updated on May 21 2023
In this article, we'll explain how to install Maven on Ubuntu 22.04. For this demonstration purpose, we're installing current LTS version JDK 17.
Maven is a build automation tool used primarily for Java projects. The first step is to install JDK because Maven needs it to execute.
Install Maven on Ubuntu 22.04
1. Keep the OS updated:
sudo apt-get update -y
2. Install JDK 17
Here we're installing current LTS version. In Ubuntu JDK 17 package is available. We can simple execute apt command to install JDK 17. If you have any specific version requirement, you can install it using binary Go to the URL: https://jdk.java.net/ where you can find other versions.
Execute following command to install JDK 17:
sudo apt-get install openjdk-17-jdk
3. Verify the Java installation:
Check the version of the Java to verify that the installation has been successfully completed.
java -version
Output:
openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-0ubuntu122.04.2)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-0ubuntu122.04.2, mixed mode, sharing)
4. Install Maven
We're installing Maven using official binary because default package has older version. To install latest version of Maven, we need to download binary from official link.
Navigate to the URL: https://maven.apache.org/download.cgi Copy the link for the "Binary tar.gz archive" file. Execute wget command to download the file.
wget https://dlcdn.apache.org/maven/maven-3/3.9.2/binaries/apache-maven-3.9.2-bin.tar.gz
Extract it in the /opt directory using tar command.
tar xvzf apache-maven-3.9.2-bin.tar.gz -C /opt/
Finally, set up environment variable. Edit .profile file. You can locate the file in the user's home directory.
nano ~/.profile
Add following lines:
M2_HOME='/opt/apache-maven-3.9.2'
PATH="$M2_HOME/bin:$PATH"
export PATH
To apply the changes, we need to execute source .profile command or exit the current terminal session and relogin.
Note: Replace the apache-maven-3.9.2 with your directory name.
That's it, now let's verify it using version check command.
mvn -version
Output:
Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c)
Maven home: /opt/apache-maven-3.9.2
Java version: 17.0.7, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-71-generic", arch: "amd64", family: "unix"
The installation process has been completed successfully.
We've seen how to install Maven on Ubuntu 22.04. Also we have install JDK 17 using apt-get command.
Related Tutorials

We'll explain how to install Maven on Ubuntu 22.04. For this demonstration purpose, we're installing current LTS version JDK 17.

We'll explain you how to install Elasticsearch on Rocky Linux 9. We'll perform CRUD operation using RESTful API. It's a distributed, RESTful and analytics.

We'll explain you how to install Elasticsearch on AlmaLinux 9. We'll perform CRUD operation using RESTful API. It's a distributed, RESTful search and analytics.