The Broken Terminal

·

2 min read

So, I just got my new laptop.

And I want to set it up so that I can do some coding on my machine.

Turns out there are 3 kinds of shell options in Mac OS; the bash profile, the zprofile, and the zshrc, and so on...

Anddd.... while experimenting on something, I kinda broke my terminal so common commands like ls or sudo or even brew are not working anymore in the terminal. It always says bash: xxxx: command not found

So, after doing some digging I found a way out of this misfortunate situation.

The key takeaway here is to set the PATH first, or one could say that we need to set the PATH to the 'standard path' that MacOS uses. And the default mandatory would be some directory in usr/local/bin. So this the step-by-step to fix the broken terminal:

  1. Open the terminal

  2. Type in the following command
    export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

  3. After that, we could open the nano or vim or vi or whatever text editor you use to add the standard path to the bash config file.

  4. For me, the command would be nano ~/.zshrc

  5. Also, don't forget to copy and paste the 'standard path' in no 2 to the content of the zsh file

  6. Save the file, and then try out the standard command you would like to use.

External Resources (Further Reading) :

https://www.cyberciti.biz/faq/change-default-shell-to-bash-on-macos-catalina/

https://iboysoft.com/howto/mac-command-not-found.html