0

This question already has an answer here:

echo $PATH returns a different result than the PATH variable I define in .bashrc. .profile is empty.

What else could be modifying the PATHvariable?

The directories listed are all things I would have entered (i.e., not done by software), probably after having read something online, but I don't remember where.

This question is for macOS Mojave, not OS X Mountain Lion. Yes, the answers are the same, but the questions are not.

marked as duplicate by Graham Miln, Nimesh Neema, abc, nohillside terminal Jun 19 at 4:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are you checking PATH in a log in session or a new shell? There is a difference unix.stackexchange.com/questions/38175/… – bmike Jun 17 at 0:39
  • Unless proven wrong, answers based on older macOS versions remain valid. So this is indeed a duplicate of the question originally asked for Mountain Lion. – nohillside Jun 19 at 21:35
1

The system default $PATH variable is set in the file /etc/paths. That file has a one directory per line structure.

There are also multiple others files that can set or modify the path variable - user specific configuration files, and shell specific ones, that only apply if you use that specific shell.

I suggest not editing the system default file (/etc/paths) as it would affect all users. To add directories to the path used in a Terminal session (and assuming that you use the default bash shell), generate a file named .bash_profile. With a text editor, create a line that adds the directories you want to the default path, e.g:

PATH=$PATH:$HOME/bin:$HOME/projects  

That will add the directories "bin" and "projects" in your home directory to the system path. You will need to either execute source .bash_profile or restart your terminal session for that change to become effective.

  • Thank you so much for a thorough and educational answer. – Herman Autore Jun 18 at 19:07
  • Can you give an example of how to use grep to find other files that modify $PATH, as is mentioned in a similar question here? For example, /Library/TeX/texbin is being appended to my path, but it's not mentioned in either /etc/paths, .bashrc, .bash_profile, or .profile. – Herman Autore Jun 18 at 19:19

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