'Factory reset mac terminal

Looks like I've messed up my terminal really badly.

Im trying simple commands like ls, cd but I get:

-bash: ls: command not found

No brew commands are found either.

I have tried following Is there any way to reset Mac terminal environment to factory settings?

But I get the same same message that -bash: rm: command not found

I can't even open my profile_bash file. Is there anyway to reset the terminal to factory settings. Nothing is working in terminal.



Solution 1:[1]

Follow these steps to reset it:

  1. Open Mac terminal
  2. Click "shell", it's on the task bar at the top of the screen
  3. Navigate to "New Command" or press the keys shift + command + N
  4. Type mv .bashrc .bashrc.bak redo the same thing for .bash_profile
  5. Now restart your terminal. It should work fine!

Try recreating but files your renamed earlier by touch .bashrc same for .bash_profile.

Solution 2:[2]

Thanks folks for contributions. Just like @Yuri Ginsburg said. export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:.

The following are steps i used to fix back ZSH terminal and to make sure all commands are working such as brew, pwd, ls and more.

How I solved the issue and be able to run all commands again? I tried the following trick.

Step 1:

Open your terminal and type export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:

Please don't close or restart the terminal cause it will fail again. Instead do the following.

Step 2:

Open your .zshrc file like this open ~/.zshrc and add the same command we used in step 1. After go to the opened text file and modify it accordingly.

# my configuration so yours might different. Try to comment most un trusted and un comment one at time.

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
ZSH_THEME="robbyrussell"
  export NVM_DIR="$HOME/.nvm"
  [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion
# PATH="/usr/local/opt/libpq/bin:$PATH"
# PATH="/Users/niyongabo/Library/Python/3.8/bin"

Notice that i did export the same command and commented other paths. The reason is that I don't know what's going so I rather un comment later when everything get back to normal

Step 3:

Save the file and go back to your terminal and write this command source ~/.zshrc to load the changes to terminal.

I hope you can fix back the issue.

macOS Monterey

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tomerikoo
Solution 2 Niyongabo Eric