2

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!

1
  • 4
    java is inside a bin folder in that location. Commented Feb 9, 2018 at 14:44

2 Answers 2

4

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"
Sign up to request clarification or add additional context in comments.

2 Comments

@rsp Working on my mac; are you editing your ".bashrc"? If so, you need to re-source it before the changes take effect. source .bashrc - edit your question, and show us the result of echo $PATH if that doesn't resolve it.
@rsp You're welcome. Welcome to SO; please remember to take the tour.
1

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

2 Comments

I found a bin folder in /Contents/Home and tried pointing to both that and java, but I still get an error msg
That's surprising, did you run the exact command in the answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.