-1

EDIT:

I have now deleted the $HOME/bin:/usr/local/bin: portion from line 1 of my .zshrc file. So now that line reads as export PATH=$PATH. This got rid of the duplicates, but it still doesnt explain where Mono and Postgres are being added to the path.

Here is what the path outputs in readable formatting:

/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Library/Frameworks/Mono.framework/Versions/Current/Commands:
/Applications/Postgres.app/Contents/Versions/latest/bin

Is there another file that is handling the exportation of these paths?

ORIGINAL:

So I really couldn't come up with a very good title, so if anyone has any suggestions please leave them in the comments.

So heres my problem. I just reset my .zshrc file to the default template by using the following command.

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

So here is my file contents for .zshrc

export PATH=$HOME/bin:/usr/local/bin:$PATH

export ZSH=$HOME/.oh-my-zsh

ZSH_THEME="agnoster"

plugins=(
  git
)

source $ZSH/oh-my-zsh.sh

The following files are either completely empty or have everything commented out: .zprofile, .bash_profile, .bashrc.

After running the source .zshrc command in my terminal followed by the echo $PATH command, this is my output.

/Users/jrobinson/bin:/usr/local/bin:/Users/jrobinson/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Postgres.app/Contents/Versions/latest/bin

Let's format this a little better so we can see what's going on:

/Users/jrobinson/bin:
/usr/local/bin:
/Users/jrobinson/bin:
/usr/local/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Library/Frameworks/Mono.framework/Versions/Current/Commands:
/Applications/Postgres.app/Contents/Versions/latest/bin

As you can see, some things are repeating such as /usr/local/bin & /Users/jrobinson/bin.

Also I had at one point Postgres installed on my computer, but no longer have it installed. Mono I still have and use, but I have no idea where it's being added to my path.

The only thing I'm defining in my path is: export PATH=$HOME/bin:/usr/local/bin:$PATH

So why am I getting these repeat things? I'm assuming it's because of some repeating code somewhere in some file, and I can't pin point where these repeats are occurring so I can delete them and clean up my PATH.

ALSO which is really weird, I have Composer installed on my computer as well, and I can use the composer command even though I haven't defined Composer in my path with /.composer/vendor/bin.

Simba
  • 23,537
  • 7
  • 64
  • 76
J. Robinson
  • 931
  • 4
  • 17
  • 45
  • 1
    Since the assignment ends with `$PATH`, you get all the directories that were already in the path, plus the new directories you add at the front. Every time you do `source .zshrc` it adds those two directories again. – Barmar Aug 30 '19 at 00:30
  • @Barmar I have since deleted the `$HOME/bin:/usr/local/bin:` from my path, and I'm still getting the Postgres folder path. Though it's not added to the new line, it must be inside of the $PATH variable, but where is this being added so I can get rid of it? – J. Robinson Aug 30 '19 at 00:43
  • 1
    Probably a system-wide startup file, like `/etc/profile`. – Barmar Aug 30 '19 at 00:48
  • Here is the contents of that file and it doesn't look like it's adding those folders: https://pastebin.com/fKGSF7sm – J. Robinson Aug 30 '19 at 00:50
  • 1
    https://scriptingosx.com/2017/05/where-paths-come-from/ – Barmar Aug 30 '19 at 00:52
  • 1
    Check `/etc/paths` – Barmar Aug 30 '19 at 00:52
  • Found it! It was in `/etc/paths.d/`. Each one, both Mono and Postgres had an individual file associated with it. So I just deleted the postgresapp file using the `sudo rm /etc/paths.d/postgresapp` command and restarted terminal. It worked. :P – J. Robinson Aug 30 '19 at 00:56
  • Whoever puts up an answer first gets the points. – J. Robinson Aug 30 '19 at 00:58
  • @J. Robinson, Please post answers as Answers, not as updates to the Question. (It's perfectly fine to answer your own question!) The text you wrote can be foind [here](https://stackoverflow.com/revisions/57719054/3). – ikegami Aug 30 '19 at 01:07
  • This question really belongs more in [apple.se] or [unix.se]. It's about how MacOS sets the default PATH, not about programming. – Barmar Aug 30 '19 at 01:19

2 Answers2

1

path_helper is a helper for constructing PATH environment variable. It's macOS exclusive.

man path_helper

Files in these directories should contain one path element per line.

Prior to reading these directories, default PATH and MANPATH values are obtained from the files /etc/paths and /etc/manpaths respectively.

A GUI app could put files into these paths. When a shell starts up, values within will be added into PATH, or MANPATH by path_helper. The whole point seems to be avoiding polluting /usr/bin or /usr/local/bin by creating symlink into them.

For bash, path_helper is called in /etc/profile on shell startup. For zsh, path_helper is called in /etc/zprofile.

Content of /etc/profile:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

path_helper -s

-s Generate Bourne shell commands on stdout. This is the default if SHELL does not end with "csh".

References

  • man path_helper
Simba
  • 23,537
  • 7
  • 64
  • 76
0

After a fresh ubuntu 20.04 install and arranging my .zshrc file, I was seeing locations in my $path even after commenting out them in .zshrc file. Further to my surprise, those were showing in bash $path as well where none were declared there (check DJANGO_HOME in image below). Used source command several times after each change with no result.

It wasted precious 10 mins of time. Then figured things were fine on a new terminal window. So killing the previous terminal and moving to a new one solved it.

enter image description here

reaganRezvi
  • 78
  • 1
  • 9