In this tutorial, i am going to show you how to install apache maven on linux ubuntu 22.04.
How to Install Apache Maven on Ubuntu 22.04
Follow the below given steps to install apache maven on Linux ubuntu 22.04:
- Step 1 – Install OpenJDK
- Step 2 – Downloading Apache Maven
- Step 3 – Setup environment variables
- Step 4 – Verify the installation
Step 1 – Install OpenJDK
Start the terminal by pressing Ctrl+Alt+T.
And run the following command on terminal to install openJDK on linux ubuntu system:
sudo apt update sudo apt install default-jdk
Verify the installation by running the following command on terminal:
java -version
Step 2 – Downloading Apache Maven
Go to the Maven download page to see if a newer version is available.
Download the Apache Maven in the /tmp
directory:
wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
Once the download is finished, extract the archive in the /opt
directory by running the following command on terminal:
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
To have more control over Maven versions and updates, i will create a symbolic link maven
that will point to the Maven installation directory:
sudo ln -s /opt/apache-maven-3.6.3 /opt/maven
Step 3 – Setup environment variables
Add 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 – Verify the installation
Run the following command on terminal to verify maven installation:
mvn -version
Conclusion
In this tutorial, i have shown to you how to install Apache Maven on Ubuntu 20.04.