I've tried the solutions listed here for instance: https://apple.stackexchange.com/questions/22859/bash-ls-command-not-found

When I do PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin it works temporarily.

When I do:

cd ~
nano .bash_profile
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH

the file changes and the save reflects but when I open a new terminal the commands are forgotten again.

  • 2
    Please take a look at editing-help.
    – Cyrus
    Commented Feb 23, 2021 at 17:50
  • 2
    Stackoverflow is for programming questions, not general computer usage/troubleshooting; Ask Different would be a better place to ask about this. But also, you'll need to do some troubleshooting yourself: first, are you using bash or zsh as your shell? Based on that, look through the startup files for that shell and try to find out what's messing up your PATH in the first place. Commented Feb 23, 2021 at 18:10
  • Are you sure your interactive shell is bash, and not something else like zsh? Have you confirmed your ~/.bash_profile is always being sourced when you open a new terminal? Commented Feb 23, 2021 at 22:39
  • Thanks everyone for the help. @ShaneBishop When I try the command ls, I get "bash: ls: command not found". So I assume it is bash? How do I confirm that it's being sourced?
    – questionasker
    Commented Feb 24, 2021 at 7:20
  • 1
    use ~/.bashrc - .bashrc vs .bash_profile Commented Feb 24, 2021 at 14:38

1 Answer 1


As pointed out by @MaximSagaydachny, you need to use your ~/.bashrc, not your ~/.bash_profile.

The commands in your ~/.bash_profile will only executed for interactive login bash sessions. They will not be executed for interactive non-login shell sessions.

The commands in your ~/.bashrc will be executed for interactive non-login bash sessions.

For more details, see the "Invocation" section of the bash man page.

Therefore, you should add your modifications to PATH in your ~/.bashrc.

You must log in to answer this question.