What modifies the PATH variable on macOS? [duplicate]

Solution 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.