I just installed Maven via Mac Catalina via command line and mvn -version was showing output. then it went away. Please help.
-
try what suggested [here](https://stackoverflow.com/questions/21028872/mvn-command-not-found-in-osx-mavrerick/21030998), the path export part in the answer – WoAiNii Jul 18 '20 at 20:34
-
Does this answer your question? [mvn command not found in OSX Mavrerick](https://stackoverflow.com/questions/21028872/mvn-command-not-found-in-osx-mavrerick) – WoAiNii Jul 23 '20 at 16:52
3 Answers
May be a long post, but in the end you will have a convenient tool to install packages and understanding of how to configure them.
Why maven "disappeared" I have no idea of, so what I would do in this situation: First of all, I would delete maven manually (find the directory and remove it along with any other files that were setup during maven installation)
Then I would highly recommend using Homebrew - a package manager for macOS To install Homebrew, open terminal and execute the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Wait for a couple of minutes (a less) until it is installed
Now, that Homebrew is installed, you have a very convenient tool to install stuff on your mac
So, you want to install Maven. You can find Maven on Homebrew
Now you just have to open your terminal again and execute
brew install maven
After a few seconds brew will display the directory it installed Maven in (by default, all Homebrew packages are installed in /usr/local/Cellar/
)
You are almost there, now you need to set the environment variable.
As described by Apache, the environment variable needs to be added to the PATH
environment variable.
Here I have some uncertainty in terms of what file to use: .bash_profile
or zprofile
. The confusion is caused by the fact that in latest macOS update (maybe several latest updates) Apple decided to use zsh shell, and so .bash_profile
became somewhat functionally equivalent to zprofile
. There are many articles on the Internet about what file to use, so you better check them out before proceeding (sorry for not providing links).
On my Catalina 10.15.6 I use .zprofile
and everything looks to work perfectly.
Once you decide what file to use, execute the following in the terminal:
nano .zprofile
An editor will open, write this:
export PATH=/usr/local/Cellar/maven/*version*/bin:$PATH
Press Control + X to exit, then Y to save changes and hit Enter to exit the editor
After that you will again be in terminal, where execute:
source .zprofile
To load it. Then close the terminal, open again and check that PATH variable is edited by executing:
env
That's it! Good luck coding!

- 129
- 7
-
I deleted all manually..restarted and then did brew install again..I worked ..thank you – ishu Sep 06 '20 at 10:10
-
For MacOs Catalina, below is what worked for me.
Terminal > Vim .zprofile
Add:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/Users/username/apache-maven-3.8.1 (This is where my maven folder is.)
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
Terminal > source ~/.bash_profile
Restart Terminal > mvn -version
Output:
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/username/apache-maven-3.8.1
Java version: 1.8.0_281, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
username@C02F ~ % java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

- 404
- 3
- 7
- 24