rsp
rsp

Reputation: 31

Java: command not found

I have installed jdk on my mac, ran /usr/libexec/java_home and found the path to java to be this: /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home

I added this line to my ~/.bashrc file:

export PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home

I still get this error message:

java: command not found

Can anyone help? I have been trying Stack Overflow solutions for hours now.

Thanks!

Upvotes: 2

Views: 18218

Answers (2)

Elliott Frisch
Elliott Frisch

Reputation: 201447

While it is sufficient to add the "bin" folder to your PATH, doing so will leave you unable to run several desirable Java standard tools (like maven, ant, sbt, scala and groovy). Instead, first set a JAVA_HOME and then add that with "bin" to your PATH. Like,

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home"
export PATH="$PATH:$JAVA_HOME/bin"

Upvotes: 4

Arnav Borborah
Arnav Borborah

Reputation: 11789

You have set your PATH to the wrong variable. Java is inside a bin folder, which you have to append to your current path. The correct command would be:

export PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin

Upvotes: 1

Related Questions