Fully set up environment for a Java developer on Mac OS

Apache-Maven

Maven configration

Now that we have successfully installed JDK, we are ready to download and install Maven in Mac OS.

Please read article to install JDK here.

Download Maven for Mac OS

Go to the Maven Download site: https://maven.apache.org/download.cgi Download the “Binary tar.gz archive” file as shown in the below image.

After downloading, extract it manual or using the below command.

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

The binaries will be extracted in the “apache-maven-3.6.3” directory. You can keep them anywhere, I have kept it in the Downloads directory for the sake of easy access.

Setting Maven Environment Variables – M2_HOME and Path

The next step is to set up the environment variables – M2_HOME and Path. We have to add the Maven bin directory to the Path variable. Open .bash_profile in your favorite text editor and add below lines to the end of it.

How to Make These Changes Permanent

If you want these commands to persist across terminal sessions:

For zsh (default in macOS Catalina and later): ~/.zshrc.

~/.zshrcexport M2_HOME="/Users/pankaj/Downloads/apache-maven-3.6.3"
PATH="${M2_HOME}/bin:${PATH}"
export PATH
source ~/.zshrc  # Or source ~/.bash_profile

Verifying the Maven Installation

Finally, run the mvn -version command to check if Maven is installed successfully.

$ mvn -version     
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/pankaj/Downloads/apache-maven-3.6.3
Java version: 13.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
Default locale: en_IN, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.1", arch: "x86_64", family: "mac"
$

The output shows maven home location, the JDK it’s using and also the Mac OS version details. Maven is successfully installed in your Mac OS. You are ready to create a maven based Java projects.

Leave a Reply

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