Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

zsh command not found bash: How to Fix Path Errors

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The "zsh: command not found: bash" error occurs because the Z shell (zsh) cannot locate the bash executable within the directories listed in your system's PATH environment variable. To fix this immediately, you must identify the absolute path of the bash binary—usually /bin/bash—and ensure that directory is included in your .zshrc configuration file. This happens most frequently after a system update, a migration to a new macOS version, or an accidental edit to the shell configuration files.

What You'll Need

  • A computer running a Unix-based system (macOS or Linux) with zsh as the active shell.
  • Administrative or sudo privileges to edit system configuration files if necessary.
  • A basic text editor (such as nano, vim, or TextEdit).
  • Knowledge of your user account password.

Step-by-Step

  1. Verify the Bash Location: Since the shell cannot find "bash" by name, you need to find where it actually lives on your hard drive. Try running the command /bin/bash. If this opens a new bash session, you know the binary exists at that specific path. If that fails, try /usr/bin/bash. Note that on most modern macOS and Linux systems, /bin/bash is the standard location.
  2. Check Your Current PATH: To see what your shell is currently looking at, type echo $PATH and press Enter. You will see a list of directories separated by colons. If you do not see /bin or /usr/bin in that list, zsh will not be able to find any standard system commands, including bash.
  3. Open the .zshrc Configuration File: The .zshrc file is a script that runs every time you start a new zsh terminal session. You need to edit this file to permanently fix the PATH. Type nano ~/.zshrc in your terminal. If the file is empty, that is normal; you are simply creating a new configuration.
  4. Add the Correct PATH Export: Scroll to the bottom of the file and add the following line: export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH". This command tells the system to look in the most common binary folders first, and then append whatever was already in the PATH variable. By placing these directories at the beginning, you ensure that system-critical tools are always accessible.
  5. Save and Exit the Editor: If you are using nano, press Ctrl + O to write the changes to the disk, press Enter to confirm the filename, and then press Ctrl + X to exit the editor.
  6. Refresh the Shell Configuration: The changes you made to .zshrc do not take effect in the current window automatically. You must tell zsh to reload the file. Type source ~/.zshrc and press Enter. Alternatively, you can simply close the terminal window and open a new one.
  7. Test the Command: Now, type bash and press Enter. You should see the prompt change, indicating that you have successfully entered a bash shell session. To return to zsh, simply type exit.

Common Mistakes

One of the most frequent mistakes is forgetting the colon (:) when adding new directories to the PATH variable. The PATH is a colon-separated list; if you omit the colon between the new path and the existing $PATH variable, the shell will treat the entire string as one long, non-existent directory path, which will break every single command in your terminal, including basic ones like ls or cd.

Another common error is using the wrong syntax for the export command. Some users mistakenly type PATH=/bin/bash. This is incorrect because /bin/bash is a file, not a directory. The PATH variable must only contain directories. If you point the PATH to a specific file, the shell will fail to find any commands within that folder. Always point to the folder containing the binary, such as /bin.

Users also frequently forget to use the tilde (~) when opening the configuration file. Running nano .zshrc without the tilde attempts to open the file in the current working directory rather than the user's home directory. Since the shell specifically looks for the configuration in the home folder, edits made to a file in a random folder will have no effect on the system's behavior.

Tips

To avoid breaking your PATH in the future, always append the existing variable to the end of your new additions using :$PATH. This ensures that you are adding to the list rather than overwriting it entirely. If you overwrite the PATH, you will lose access to all system utilities until you manually restore the variable for that session.

If you find yourself needing to switch between zsh and bash frequently, consider creating an alias in your .zshrc file. For example, adding alias gobash="/bin/bash" allows you to simply type "gobash" to jump into a bash environment without worrying about whether the PATH is perfectly configured for the short name.

Keep a backup of your .zshrc file before making major changes. You can do this by running cp ~/.zshrc ~/.zshrc.bak. If you make a mistake that locks you out of your commands, you can restore the backup using a full path command like /bin/cp ~/.zshrc.bak ~/.zshrc.

Troubleshooting

If you have followed the steps above and still receive the "command not found" error, first check if bash is actually installed on your system. While rare on macOS and Linux, some minimal Docker containers or stripped-down Linux distributions do not include bash by default. Run ls /bin/bash. If the terminal returns "No such file or directory," bash is not installed. You will need to install it using your system package manager (e.g., sudo apt install bash on Ubuntu/Debian).

If bash is installed but the error persists, check for permission issues. It is possible that the bash binary has had its execution permissions removed. You can check this by running ls -l /bin/bash. You should see "x" in the permission string (e.g., -rwxr-xr-x). If the "x" is missing, you can restore execution permissions with sudo chmod +x /bin/bash.

In cases where the terminal is so broken that you cannot even run nano or source, you can temporarily restore your PATH for the current session. Type export PATH=/usr/bin:/bin:/usr/sbin:/sbin and press Enter. This will immediately restore access to basic commands, allowing you to then open the .zshrc file and apply the permanent fix described in the step-by-step section.

Frequently Asked Questions

Why did my terminal switch from bash to zsh?

Apple changed the default shell from bash to zsh starting with macOS Catalina. This was primarily due to licensing differences between the newer versions of bash (GPLv3) and the zsh license, which is more permissive for commercial distribution.

Is zsh better than bash?

Both are powerful shells. Zsh is generally considered more feature-rich, offering better auto-completion, advanced theme support via frameworks like Oh My Zsh, and more flexible globbing patterns for file searching.

Can I change my default shell back to bash?

Yes, you can change your default shell by using the command chsh -s /bin/bash. You will be prompted for your password. After restarting the terminal, you will be back in bash.

What is the difference between .bashrc and .zshrc?

These are configuration files for their respective shells. .bashrc is read by bash, and .zshrc is read by zsh. Settings added to one will not affect the other; if you want the same aliases or PATH settings in both, you must add them to both files.

Does this fix apply to Windows?

This specific fix is for Unix-like environments. If you are seeing this error on Windows, you are likely using WSL (Windows Subsystem for Linux) or Git Bash. The steps are similar, but you must ensure you are editing the configuration file within the Linux distribution you have installed.