How to Install Apache Maven on Ubuntu 22.04

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/maven.sh command on a terminal window to open the maven.sh configuration file:

sudo nano /etc/profile.d/maven.sh

Then add the following code in maven.sh 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/maven.sh

Finally, load the environment variables using the source command:

source /etc/profile.d/maven.sh

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.

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

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *