Maven - Installation details

Prerequisites

jdk

See JavaInstallation.org for details about installing jdk

Using Homebrew

https://formulae.brew.sh/formula/maven#default

Using Maven binaries

Step 1: Download the Maven Binaries

Go to the URL: https://maven.apache.org/download.cgi Copy the link for the “Binary tar.gz archive” file.

Then run the following commands to download and untar it.

$ tar -xvf apache-maven-3.6.3-bin.tar.gz

Step 2: Setting M2_HOME and Path Variables

Linux

Use .bashrc for Linux computers and .zshrc for Macbooks.

https://maven.apache.org/install.html

Add the following lines to .bashrc or .zshrc

export M2_HOME=/home/h/Documents/apache-maven-3.8.6
export PATH=$M2_HOME/bin:$PATH

Relaunch the terminal or execute source .profile to apply the changes.

Windows

  1. Download the zip file for mvn and unzip it into a location.
  2. After that, set M2_HOME in environment variables. Don’t include the \bin folder, just the path to mvn folder. For example – C:\Users\vardh\Documents\apache-maven-3.8.6
  3. After that, update PATH in environment variables. Add this: %M2_HOME%\bin (If you are looking at the old view, the entries will be separated by semi-colon)

Verify the Maven installation

Execute mvn -version command and it should produce the following output.

[h@h-p50-20eqs27p03 ~]$ mvn -version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /home/h/Documents/apache-maven-3.8.6
Java version: 18, vendor: Oracle Corporation, runtime: /home/h/Downloads/jdk-18
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.19.11-arch1-1", arch: "amd64", family: "unix"

Tags

Java installation


Links to this note