Installing Maven on Linux, Windows and Mac

Description

This post will show you to install and configure maven on Windows, Linux and Mac. Before performing the installation, make sure the Java Development Kit is properly installed and configured. For Linux you can refer to my post

Linux

For this installation I have performed the task on Ubuntu 18.06 LTS 64 bit, but also referred the same for other distros, it all turned out to be working perfectly. You can use the manual way to perform installation on other distros. For this make sure the java

Installing using the Package Manager

sudo apt-get install maven

Installing Manually

Navigate to Apache Maven’s official web site and and download the latest version (3.5.4 as of writing this article) the binary tar.gz package.

1. Unpack the Tar file

tar zxvf apache-maven-3.5.4-bin.tar.gz 

2. Move the folder to the opt folder

sudo mv apache-maven-3.5.4 /opt/

3.Create a Maven profile file

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

3.1. Add these lines in the “.sh” file

export M2_HOME=/opt/apache-maven-3.5.4
export M2=$M2_HOME/bin 
PATH=$M2:$PATH

4. Reload the “sh” file in the system

source /etc/profile.d/maven.sh
. /etc/profile.d/maven.sh

5. Check the Maven installation

mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: /opt/apache-maven-3.5.4
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_181/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-23-generic", arch: "amd64", family: "unix"

Windows

Download the binary file in .zip or tar.gz does not matter extract the folder under C drive if you want you may create the folder wherever you want, but to make it easier you shall consider practical way of it, after you extract the folder

Right Click Computer and click on Properties

windows1

On the left side of the properties, click on Advanced system settings

windows2

Below click on Environment Variables

windows3

Click on “New” on Users variables and enter the details as below

windows4

and on system variables find PATH and add the line

windows5

and now lets launch command line and see if its configured

windows6

Mac OS

Normally maven comes out of package on mac os operating systems since 10.6.8 Snow Leopard, test if the maven is installed on your mac launch terminal and enter the command:

mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 19:31:09+0200)
Maven home: /usr/share/maven
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
Tugruls-Mac:~ tugrulaslan$

to install it manually as the above linux package file download and exract the file the same way

tar -zxvf apache-maven-3.1.1-bin.tar.gz
sudo mv apache-maven-3.1.1 /usr/lib/maven
vim ~/.bash_profile

and these lines

export M2_HOME=/usr/lib/maven
export PATH=$PATH:$M2_HOME/bin

before you proceed the maven installation, please make sure that you have successfully carried out jre and jdk installation and configuration

Leave a Reply

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