How to ensure maven is installed in mac
Solution 1
I had the same issue before and resolved it by the following steps
1: Down load Maven here
2: Open Terminal
3: Type cd ~/
4: Type touch .bash_profile
5: Type open -e .bash_profile to open .bash_profile in TextEdit
6: Type the following in the TextEdit
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdkx.x.x_xxx.jdk/Contents/Home
export M2_HOME=/User/username/[Your file location]/apache-maven-3.6.0/
export PATH=$PATH:$M2_HOME/bin
alias mvn='$M2_HOME/bin/mvn'
- jdkx.x.x_xxx.jdk : Your java version
- username: Your username
7: Save the file
8: Type source .bash_profile
9: Type mvn -version
And you will see the following message:
Apache Maven 3.1.1 Maven home: /Users/username/Maven/apache-maven-3.1.1 Java version: 1.7.0_51, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.9.1", arch: "x86_64", family: "mac"
Hope this helps!
Solution 2
for how to install maven in mac
and how to make it take effect immediately
and how to make sure maven installed correctly
, please refer my answer in another post.
In short, all step of manual install is:
download binary (latest apache-maven-3.6.3-bin.zip) from official site
uncompress (apache-maven-3.6.3-bin.zip) it to somewhere (/Users/crifan/dev/dev_tool/java/maven)
add the
bin path of maven
(/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin) intoPATH
normally is:
- edit your start script (
.bashrc
/.zshrc
/ ...)vi ~/.bashrc
- add following config into it
export PATH=/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin:$PATH
- make it take effect (right now, in current console)
source ~/.bashrc
- verify can found maven
which mvn
- and check its version
mvn --version
example output:
➜ bin pwd
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin
➜ bin ll
total 64
-rw-r--r--@ 1 crifan staff 228B 11 7 12:32 m2.conf
-rwxr-xr-x@ 1 crifan staff 5.6K 11 7 12:32 mvn
-rw-r--r--@ 1 crifan staff 6.2K 11 7 12:32 mvn.cmd
-rwxr-xr-x@ 1 crifan staff 1.5K 11 7 12:32 mvnDebug
-rw-r--r--@ 1 crifan staff 1.6K 11 7 12:32 mvnDebug.cmd
-rwxr-xr-x@ 1 crifan staff 1.5K 11 7 12:32 mvnyjp
➜ bin vi ~/.bashrc
➜ bin source ~/.bashrc
➜ bin echo $PATH
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin:xxx
➜ bin which mvn
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin/mvn
➜ bin mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3
Java version: 1.8.0_112, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
for detailed info please refer my (Chinese) post: 【已解决】Mac中安装Gradle
Solution 3
I was also facing the same issue. Somehow I was able to resolve this. Sharing steps :
Perquisite is, to have maven and java downloaded in your system. If these don't exist than, download, extract and follow below steps.
Open .bash_profile
sudo vi .bash_profile
Add these contents ( make sure you point to correct locations as your system, in below example I have used installation directories of my machine)
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/Applications/apache-maven-3.6.0
export M2_HOME
export PATH=${PATH}:${JAVA_HOME}/bin:${M2_HOME}/bin
export PATH
save and exit.
source .bash_profile
fire mvn -version
you will be able to get the below output, which implies maven is installed.
mvn -v
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T00:11:47+05:30)
Maven home: /Applications/apache-maven-3.6.0
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"
Krunal
Contact me, if you're looking for a CTO or Engineering Director/VP. contact: +91 - 9737007007 mail: [email protected] Following some great SO users....
Updated on June 05, 2022Comments
-
Krunal almost 2 years
I'm trying to install Maven in my Mac system (MacOS: High Siera, Version: 10.13.3).
I followed all steps from this document: Installing Apache Maven
- Donloaded tar file from a link: apache-maven-3.5.2-bin.tar.gz extracted in same directory
echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
export PATH=/opt/apache-maven-3.5.2/bin:$PATH
All command executed without any error. Even tried using this also: Installation of the Maven command line tools.
But still system show an error when I try execute
mvn
command:-bash: mvn: command not found
How can I ensure, whether maven is properly installed in my system or not? Or my question can be: How to install maven in macOS?
I tried solutions from following SO questions also but nothing works:
- install maven on mac
- Installing maven 3.0.4
- Maven Install on Mac OS X (I can't use brew, most upvoted solution here)
-
Katakam Nikhil over 3 yearsI am seeing [ERR_INVALID_CALLBACK]: Callback must be a function. error when I run any mvn command. What should I do?