I was trying to add JAVA_HOME in the path variable.
I downloaded Java JDK and done following:

  • nano ~/.bash_profile
  • added following lines and saved the file:

    export JAVA_HOME=$(/usr/libexec/java_home)
    export PATH=$JAVA_HOME/bin=$PATH
  • source ~/.bash_profile

After that I tried to open bash file again using:

nano ~/.bash_profile

It shows:

-bash: nano: command not found

I tried other commands too such as brew doctor, curl, vim, java -version etc. All of them shows command not found error.

What is the solution for this? How can I restore my system?

Updated: Solution that I used:

I run the following commands to set the standard default path that Mac OS uses in the command line:

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

The line

export PATH=$JAVA_HOME/bin=$PATH

should read

export PATH="$JAVA_HOME/bin:$PATH"

(note the = changing to : towards the end, and I also double-quoted the value for safety in case there are any spaces in any of the pathnames)

You will have to change that using the full path to the nano editor (/usr/bin/nano on macOS)

/usr/bin/nano ~/.bash_profile

... and then restart your shell/terminal. Using source on shell startup files is almost never a good idea as that would add to the existing PATH variable (and possibly to others as well) rather than modify a "clean" version of the variable, and it may have other interesting side-effects if things like tmux or screen are automatically started.

You could also temporarily get a sensible value for PATH so that you can repair the file with nano using

PATH=$(getconf PATH)
nano ~/.bash_profile

The getconf PATH command returns a PATH string that is supposed to cover all standard utilities. On macOS, this includes the nano editor.


Try to run nano with an absolute path like

/usr/bin/nano ~/.bash_profile


/bin/nano ~/.bash_profile

(I don't know where nano is located on your system.)

When adding $JAVA_HOME to PATH in your .bash_profile you have to use : instead of =

export PATH="$JAVA_HOME/bin:$PATH"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.