Search code examples
macosshellterminalpathzsh

Why did this permanently mess up my terminal from being able to run commands?


Hi I broke my terminal environment or something because I have no idea how any of this stuff works and I was trying to install tartube by following the installation instructions for it on Github. So mindlessly copy/pasting the commands in the guide into terminal... then after I ran these commands for troubleshooting the install:

echo "export PATH="python3 -m site --user-base/bin:$PATH"" >> ~/.zprofile

source ~/.zprofile

Now this is what my terminal looks like after opening it and trying to run some basic commands:

Last login: Sat Nov 11 20:10:15 on ttys000
/Users/censoringmyfullname/.zprofile:export:6: not valid in this context: -m
/etc/zshrc:7: command not found: locale
/etc/zshrc_Apple_Terminal:104: command not found: mkdir
censoringmyfullname@supername-mbp ~ % zsh
zsh: command not found: zsh
censoringmyfullname@supername-mbp ~ % brew
zsh: command not found: brew
censoringmyfullname@supername-mbp ~ % sudo
zsh: command not found: sudo
censoringmyfullname@supername-mbp ~ % 
censoringmyfullname@supername-mbp ~ % echo $PATH
/opt/homebrew/bin:/opt/homebrew/bin:/Users/censoringmyfullname/.pyenv/bin:python3

So now my terminal says weird stuff when I open it and none of the commands work. I've tried a bunch of internet guides to reset zsh shells, whatever that is, by some variation of PATH = "gibb:/erish/gobblygook" and nothing works.

Any advice or especially commands that magically fix this with no explanation would be wholly appreciated by grug, so that I can return to world of concepts I understand, thank you !!!! (I will venmo and/or send good vibes - thank you)

I read this https://support.apple.com/en-us/HT208050 and this https://youngstone89.medium.com/setting-up-environment-variables-in-mac-os-28e5941c771c and also this Command not found when opening terminal, possible conda issue?

And none helped


Solution

  • The quoting in that command is completely messed up, so the first thing to do is remove the line it added from your ~/.zprofile file. From the error message, that appears to be line #6 in the file (and probably the last line, unless something else has been added after it). The line will look something like this:

    export PATH=python3 -m site --user-base/bin:/lots/more/stuff/here
    

    You can do this with a command-line editor if you're comfortable with one, but you'll need to specify the full path to the editor, like /usr/bin/nano ~/.profile or /usr/bin/vi ~/.profile. If you prefer to use a GUI editor, I recommend BBEdit for things like this. Even in free/unpaid mode, it can edit hidden files (like .zprofile), and it doesn't mess things up by adding formatting, smart quotes, etc like many editors do.

    Once you've removed that, open a new Terminal window and make sure things are working normally, then run this to add the correct line to your ~/.zprofile. I think this'll do the right thing:

    echo 'export PATH="'"$(python3 -m site --user-base)"'/bin:$PATH"' >> ~/.zprofile
    source ~/.zprofile