4

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

  1. Donloaded tar file from a link: apache-maven-3.5.2-bin.tar.gz extracted in same directory
  2. echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
  3. 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

enter image description here

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:

Krunal
  • 77,632
  • 48
  • 245
  • 261
  • Directory from step 1. should be the same as in step 3. Does the directory /opt/apache-maven-3.5.2/bin actually exists? – user158037 Feb 26 '18 at 11:52
  • @user158037 - No, I think no.. Let me check it... – Krunal Feb 26 '18 at 12:44
  • 2
    You have to download it manually unpack it to an appropriate location for example `/usr/local/apache-maven-3.5.3` and add the `bin` directory of this to `PATH` ..to do that permanently add this setup to `.bashrc_profile`... – khmarbaise Feb 26 '18 at 16:29

3 Answers3

4

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!

Community
  • 1
  • 1
Mimi
  • 53
  • 3
4

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:

  1. download binary (latest apache-maven-3.6.3-bin.zip) from official site

  2. uncompress (apache-maven-3.6.3-bin.zip) it to somewhere (/Users/crifan/dev/dev_tool/java/maven)

  3. add the bin path of maven (/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin) into PATH

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

crifan
  • 12,947
  • 1
  • 71
  • 56
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"
Bhaskar
  • 159
  • 1
  • 2
  • 17