0

I always run into problems with my terminal because the command I'm trying to use is "not found". Then when I try to install that command I have another command that is also "not found" that I need to install. Also whenever I get something like sudo it works for that session but next time I open terminal I have to reinstall the commands all over. If I do

echo $PATH

It returns

/opt/local/bin:/opt/local/sbin:’/usr/local/bin:??

I received a temporary solution which works decently but I have to redo everytime I open terminal so if someone could explain to me how to fix this permanently that would be great. I know echo $PATH isnt supposed to return that.

1
  • Yes that is copied and pasted form terminal Commented Sep 14, 2017 at 23:38

1 Answer 1

1

You probably don't need to uninstall or reinstall any commands, you probably just need to fix whatever's causing your PATH variable to get corrupted.

To set it to reasonable defaults for the current shell session, type this:

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

Note that this only fixes it for the current shell session, and the next Terminal window you open will be back to the broken state.

To fix it for next time, you'll need to find where it's getting set wrong and fix it there.

In modern macOS, system-wide path stuff is set up in /etc/paths and /etc/paths.d/* (those are text-based config files). So check those first and make sure they look sane.

Also, there are system-wide shell startup scripts in /etc/, such as /etc/profile and /etc/bashrc, among others. It's fairly common to set or add to your PATH in shell startup scripts. If you, or some installer or package manager or install script has edited those, you may need to see what it did and fix it (that is, view those script files in a text editor and edit them to fix them if you find mistakes). Which ones you need to check depend on which shells you're using, how you're invoking and using them (i.e. as login, non-login interactive, or non-interactive shells), and which shell startup script files exist (some take precedence over others, so the presence of some files may cause other files not to get run). You'll need to check the man pages for the shells you're using for details on which shell startup scripts they run in which situations.

Then you need to check your own personal shell startup scripts in your own home directory. Again, which scripts get run depend on which shell you use, how you're invoking it, and which script files exist, so you need to check the man pages. You'll probably end up needing to look at ~/.profile and ~/.bashrc.

One last note: Assuming you copy/pasted that output text, it looks like it contains a curly quote, which suggests one of your shell startup scripts accidentally contains a curly quote. Be careful of editing shell scripts and other computer-readable text-based file formats (source code, HTML, CSS, JavaScript, JSON, XML, .plists, etc.) in GUI word processors / text editors. Make sure to turn off all the text substitution features like "smart quotes" and "smart dashes" or you'll end up accidentally getting curly quotes where you wanted a straight quote, or an em dash where you wanted two hyphens. Most computer-readable formats only consider straight quotes to be syntactically meaningful.

16
  • -bash: /etc/paths: Permission denied -bash: /etc/paths.d/40-XQuartz: Permission denied Commented Sep 14, 2017 at 23:39
  • I just typed those in as you typed them but should I run a command on them? If I do ls they return different things Commented Sep 14, 2017 at 23:41
  • ls /etc/paths /etc/paths Commented Sep 14, 2017 at 23:42
  • @TylerBloom Those are text files. You want to edit them with a text editor with root privileges. So for example if you know how to use vi, you could sudo vi /etc/paths.
    – Spiff
    Commented Sep 14, 2017 at 23:42
  • sorry I'm not sure what a text editor is. If I run sudo vi it returns /usr/local/bin /usr/bin /bin /usr/sbin /sbin ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~~ ~ ~ ~ ~ ~ ~ "/etc/paths" 5L, 45C each ~ on a seperate line though Commented Sep 14, 2017 at 23:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .