commands not found on zsh

前端 未结 16 1564
梦毁少年i
梦毁少年i 2020-12-04 06:30

I am using the z Shell (zsh) instead of the default bash, and something wrong happen so that all commands who used to work are no longer recognized:

<         


        
相关标签:
16条回答
  • 2020-12-04 07:01
    1. Use a good text editor like VS Code and open your .zshrc file (should be in your home directory. if you don't see it, be sure to right-click in the file folder when opening and choose option to 'show hidden files').

    2. find where it states: export PATH=a-bunch-of-paths-separated-by-colons:

    3. insert this at the end of the line, before the end-quote: :$HOME/.local/bin

    And it should work for you.

    You can test if this will work first by typing this in your terminal first: export PATH=$HOME/.local/bin:$PATH

    If the error disappears after you type this into the terminal and your terminal functions normally, the above solution will work. If it doesn't, you'll have to find the folder where your reference error is located (the thing not found), and replace the PATH above with the PATH-TO-THAT-FOLDER.

    0 讨论(0)
  • 2020-12-04 07:01

    For me just restarting my terminal seemed to fix the issue.

    0 讨论(0)
  • 2020-12-04 07:02

    In my case, it was by mistake the commented code was uncommented at the very first line.

    # If you come from bash you might have to change your $PATH.
    

    The hash was removed. After adding it back worked fine.

    I just posted this here so someone might find this helpful. Because it's just start of the line and might be deleted by mistake like I had done. And seems there's no solution after trying several ways.

    0 讨论(0)
  • 2020-12-04 07:03

    Uninstall and reinstall zsh worked for me:

    sudo yum remove zsh
    sudo yum install -y zsh
    
    0 讨论(0)
  • 2020-12-04 07:05

    If you like me, you will have two terminals app, one is the default terminal with bash as the default shell and another iTerm 2 with zsh as its shell. To have both commands and zsh in iTerm 2 from bash, you need to do the following:

    On iTerm 2, go to preferences (or command ,). Then go to the profile tab and go down to command. As you can see on the picture below, you need to select command option and paste path of zsh shell (to find the path, you can do which zsh).

    At this point you will have the zsh as your default shell ONLY for iTerm 2 and you will have bash as the global default shell on default mac terminal app. Next, we are still missing the commands from bash in zsh. So to do this, you need to go on your bash (where you have your commands working) and get the PATH variable from env (use this command to do that: env | grep PATH).

    Once you have that, go to your iTerm 2 and paste your path on "send text at start" option.

    export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin && clear
    

    Just reopen iTerm 2 and we are done!

    0 讨论(0)
  • 2020-12-04 07:06

    A way to edit the .zshrc file without doing it through iTerm2 or native Terminal on macOS is to use a terminal in another application. For example, I used the terminal as part of VSCode and was able to find and edit the file.

    0 讨论(0)
提交回复
热议问题