Friday, April 27, 2018

install MAVEN on MAC OS Globally


Hello Everyone,

 Today I am going to explain that how to install MAVEN on Mac OS in few easy steps. Before we start the process, Lets get familiar with Maven. Maven is a command-line tool for building Java applications. Maven is used to compile your angular js, java project in to an application. The Maven project provides a simple ZIP file containing a precompiled version of Maven for your convenience. There is no installer. It’s up to you to set up your environment to run Maven. The installation of Apache Maven is a simple process of extracting the archive and adding the bin folder with the mvn command to the PATH. 



Maven is written in JavaThus you will need to install Java JDK. Once Java is installed ensure that following command on terminal prints java version.



java - version  must display the right java version number.

Now please open a new Terminal window.

Step 1. Check If MAVEN is already installed. Type command $mvn --version  on the terminal and hit enter. If command not found means Maven is not installed on the system.

             







Step 2. Download Maven from internet. 
You can reach to Maven download page by click here and download apache-maven-3.5.3-bin.zip file.














Step 3: After that move the downloaded folder to other preferred location.
You can use this command to move folder ($sudo mv /Users/srajpoot/Downloads/apache-maven-3.5.3/ /Users/srajpoot/)

Step 4: Set the System Variables
    v M2_HOME
    v PATH

Ø  To set M2_HOME type $ export M2_HOME=/Users/srajpoot/apache-maven-3.5.3/ and hit enter.This will set M2_HOME path. This is path where my apache Maven folder is located.
Ø  To set PATH type $ PATH=$PATH:/Users/srajpoot/apache-maven-3.5.3/bin/  and hit enter.

Step 5: Type $mvn --version    to check Maven is installed.
Output will be like :
zccwp-jvzfrc2:~ srajpoot$ mvn --version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T14:49:05-05:00)
Maven home: /Users/srajpoot/apache-maven-3.5.3
Java version: 1.8.0_161, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.4", arch: "x86_64", family: "mac"

So this means Maven is ready for use in this session. But when you open new terminal window, Maven will not be available for use. So how to install Maven globally ? Please follow next steps to get solution.

Step 6: Create .bash_profile , use command $ touch .bash_profile to create profile.












This file will be created under home folder. This is a hidden file, so you will need to show hidden files and relaunch Finder.
Command to show hidden files: $ defaults write com.apple.finder AppleShowAllFiles TRUE
Command to hide hidden files: $ defaults write com.apple.finder AppleShowAllFiles FALSE










Step 7: Open .bash_profile with TextEdit and put below lines into the file.
export M2_HOME=/Users/srajpoot/apache-maven-3.5.3
export PATH=$PATH:/Users/srajpoot/apache-maven-3.5.3/bin












Save and close file.

Step 8: Open new terminal window & check $mvn --version.You will be able to access Maven any time globally on your Mac.


Happy Coding!! Thank You!! Hope above steps might have helped you on Maven installation on Mac OS. 

Please leave comment/question if you are not able to install Maven properly on your Mac OS. 

Also check my other post on install Ant on Mac os here.