Open In App

How To Install Maven On Linux?

Last Updated : 05 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Maven is your software program development sidekick! Maven, crafted using the Apache Software Foundation, is the go-to device for simplifying the complex international of build automation and task management. It's designed to permit you to be conscious of coding while effortlessly managing obligations like constructing, checking out, and deploying initiatives.

Think of Maven as your task agency wizard. With its XML-based configuration, Maven makes mission management a breeze, thanks to the usage of conventions that assist you in diving instantly into improvement without getting slowed down through construction process intricacies.

Steps to install Maven on Linux

Note: We are installing Maven on Ubuntu Linux (20.04 LTS)

Step 1: Update local packages

  • sudo apt update: This command is used to update the local package index on your machine.
  • sudo apt upgrade: This command is used to upgrade the installed packages on your system to the latest available versions.
sudo apt update && sudo apt upgrade -y

Repo UpdateStep 2: Install JDK

Since Maven is primarily built using Java. Install JDK. You need the Java Development Kit (JDK) in addition to the JRE in order to compile and run Java-based software. To install the JDK, execute the following command, which will also install the JRE:

sudo apt install  openjdk-11-jdk

Install JDK

Step 3: Verify Installation

java --version

JAVA-Version

Step 4: Install Maven.

sudo apt install maven -y

Maven

Step 5: Verify Installation

mvn --version

mvn-v

Manual Installation

Step 1: This command is used to update the local package index on your machine.

sudo apt update

update

Step 2: Since Maven is primarily built using Java. Install JDK. You need the Java Development Kit (JDK) in addition to the JRE in order to compile and run Java-based software. To install the JDK, execute the following command, which will also install the JRE:

sudo apt install default-jdk

Step 3: Installing the java on linux machine

jdk

sudo wget http://www-eu.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz 

wget

Step 4: Extracting the maven on linux

sudo tar -zxvf apache-maven-3.5.3-bin.tar.gz

tar

Step 5: Move the extracted Maven directory to the desired location. Example, we move it to /opt/:

sudo mv apache-maven-3.5.3 /opt/maven

mv

Step 6: The command nano ~/.bashrc is used to open and edit the user-specific Bash configuration file.

nano ~/.bashrc

bashrc

Step 7: Add following to /.bashrc

export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

export

Step 8: The command source ~/.bashrc is used to apply the changes made in the ~/.bashrc file immediately to the current Bash session.

source ~/.bashrc

src

Step 9: Verify Installation

mvn --version

mvn-v


Next Article

Similar Reads