4

If I do echo $PATH I get the following:

/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/share/npm/bin:/usr/local/share/python:/opt/X11/bin:/Users/kh/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

This is in my ~/.zshrc file:

export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/share/npm/bin:/usr/local/share/python:/opt/X11/bin:$HOME/.rvm/bin:$PATH

I've had to manually add /usr/local/etc... at the front of this file because homebrew was complaining.

I've searched for all possibles files (I know of) to find where $PATH is being built from. But to no avail. These are

~/.bash_profile
~/.bashrc
~/.profile

Any suggestions.

1
  • Was this question ever given an accepted answer or otherwise solved? (It is showing as being 8 years old...) Commented Apr 11, 2022 at 18:37

4 Answers 4

4

Default paths are defined in /etc/paths on macOS. As a sub-process inherits environment variables and you explicitly set /usr/bin/ in your $PATH you have duplicate entries.

To remove the duplicate entries, you can use:

typeset -U PATH

The consequence of the above command is that only the first instance of any given directory path in the value of $PATH will be kept, while later duplicates are removed automatically. The effect is persistent in the current shell session, so adding new duplicates to the variable will be prevented.

2

I don't know which other file is setting your $PATH but the duplicated entries are

/opt/X11/bin
/usr/bin
/usr/local/bin
/usr/sbin

All of these are set in your ~/.zshrc so all you need to do is not set them there. In any case, these should all be in the default $PATH and there is no need to add them. Most systems come with a default $PATH that will include these directories, additions made in users' ~/.zshrc files should only add non-standard directories.

Change your $PATH declaration to

export PATH=/usr/local/sbin:/usr/local/share/npm/bin:/usr/local/share/python:$HOME/.rvm/bin:$PATH

0

According the the ZSH manual page:

STARTUP/SHUTDOWN FILES

Commands are first read from /etc/zshenv; this cannot be overridden. Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the former affects all startup files, while the second only affects global startup files (those shown here with an path starting with a /). If one of the options is unset at any point, any subsequent startup file(s) of the corresponding type will not be read. It is also possible for a file in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and GLOBAL_RCS are set by default.

Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

Thus, you may want to check:

/etc/zshenv
/etc/zshrc
/etc/zlogin

and any files they happen to source. Since you are OS X, it is likely you'll find something like:

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

which, according to the path_helper man page, will also look in:

/etc/paths
/etc/paths.d/*
1
  • Nothing in:/etc/zshenv /etc/zshrc /etc/zlogin and can't change order in /etc/paths as some command may rely on using system default version in /usr/bin rather than /usr/local/bin Commented Jun 9, 2013 at 18:50
-1

You can set additional paths to PATH using the following syntax:

PATH=$PATH:/additonally_location

So I think that PATH isn't duplicated.

4
  • It is being duplicated though and I want to try and figure out where Commented Jun 9, 2013 at 18:25
  • zsh search for a few files in you home, verify if one is duplicating your path: ~/.zshenv, ~/.zprofile, ~/.zlogin Commented Jun 9, 2013 at 18:29
  • Thanks. But i've just done that all files are empty or dont exist at all Commented Jun 9, 2013 at 18:36
  • @showFocus in that case please update your question to list the zsh files you have searched through, .bashrc and .bash_profile are irrelevant. Commented Jun 9, 2013 at 19:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.