Java: command not found

11,943

Solution 1

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"

Solution 2

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
Share:
11,943
rsp
Author by

rsp

Updated on June 14, 2022

Comments

  • rsp
    rsp almost 2 years

    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!

    • khelwood
      khelwood about 6 years
      java is inside a bin folder in that location.
  • rsp
    rsp about 6 years
    I found a bin folder in /Contents/Home and tried pointing to both that and java, but I still get an error msg
  • Arnav Borborah
    Arnav Borborah about 6 years
    That's surprising, did you run the exact command in the answer?
  • Elliott Frisch
    Elliott Frisch about 6 years
    @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.
  • Elliott Frisch
    Elliott Frisch about 6 years
    @rsp You're welcome. Welcome to SO; please remember to take the tour.