3

It is suppose to be easy, but I'm having great difficulty installing Maven on to my mac 10.11.4.

I have created M2_HOME and PATH for Maven, but when I type in mvn --version, the terminal tell me

/Users/justin/apache-maven-3.3.9/bin/mvn: line 53: uname: command not found
/Users/justin/apache-maven-3.3.9/bin/mvn: line 143: which: command not found
/Users/justin/apache-maven-3.3.9/bin/mvn: line 171: which: command not found
Error: JAVA_HOME is not defined correctly.
  We cannot execute 

Why is this happening?

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Thor
  • 9,638
  • 15
  • 62
  • 137
  • Hmm, if `uname` and `which` are not defined, that's rather strange. I would be very surprised if they do not work on a Mac. Do they work on your console at all? These are core commands that should work everywhere, even without Java or Maven installed. What does `echo $PATH` give you? – halfer Aug 14 '16 at 21:21

2 Answers2

2

You need JAVA_HOME to be defined, as covered in installation guide.

Check out this answer for additional details for MacOS.

Community
  • 1
  • 1
B.Gen.Jack.O.Neill
  • 8,169
  • 12
  • 51
  • 79
  • 3
    the installation guide simply said "Ensure JAVA_HOME environment variable is set and points to your JDK installation", but it does not give you details on how to do so, especially for complete noobs like me – Thor Aug 14 '16 at 10:30
2

For macOs Ventura 13.1

If you installed java openJdk version 11 using Homebrew:

brew install java11

Then, your java is installed on:

/opt/homebrew/Cellar/openjdk@11/11.0.17/libexec/openjdk.jdk/Contents/Home

So, you must understand that this is you JAVA_HOME environment variable.

You need to add the java '/bin' folder to your PATH environment variable in order to have it working on your terminal. Also, you need to create the JAVA_HOME environment variable in order to maven to know about your java.

Therefore, you must open:

/Users/<yourUser>/.zshrc

Add

export JAVA_HOME="/opt/homebrew/Cellar/openjdk@11/11.0.17/libexec/openjdk.jdk/Contents/Home"
export PATH="/opt/homebrew/opt/openjdk@11/bin:$PATH" 

Save your changes, close the file. Now you can open your terminal and type:

java -version

and then,

mvn -version

and this is what you should get:

example@example441 ~ % java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment Homebrew (build 11.0.17+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.17+0, mixed mode)

example@example441 ~ % mvn -version
Apache Maven 3.8.7 (xxxxxxxxxxxxxxxxxxxxxxxxxxx)
Maven home: /opt/homebrew/Cellar/maven/3.8.7/libexec
Java version: 11.0.17, vendor: Homebrew, runtime: 
opt/homebrew/Cellar/openjdk@11/11.0.17/libexec/openjdk.jdk/Contents/Home
Default locale: pt_BR, platform encoding: UTF-8
OS name: "mac os x", version: "13.1", arch: "aarch64", family: "mac"