This article will show you how to configure apache maven in your macOS
Locate your maven install directory
eg. Suppose your maven install location as below:
/Users/yourname/Development/apache-maven-3.9.3
Create or Update .bash_profile file
Create a .bash_profile in root folder if you don’t have one, if there’s one, update the file, add below content at the end of the file.
export M2_HOME="/Users/yourname/Development/apache-maven-3.9.3"
PATH="${M2_HOME}/bin:${PATH}"
export PATH
Save and close terminal app, relaunch terminal and run maven command to check version
mvn -v
If you still got something error message like : “zsh: command not found: mvn”, try to run below command to apply the change
source .bash_profile
If you have below error message, make sure to double check your java home settings
The JAVA_HOME environment variable is not defined correctly,
Correct java home settings should be something like below, DON’T MISS the “Contents/Home” part.
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-xx.x.x/Contents/Home"
PATH="$JAVA_HOME/bin:$PATH"
After above command, you should be able to use mvn command via terminal app
Reference
https://www.digitalocean.com/community/tutorials/install-maven-mac-os