3

Why doesn’t the /etc/paths file include the /usr/local/sbin directory on macOS?

$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I would have expected:

$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/local/sbin
/usr/sbin
/sbin

Note. — The /etc/paths file is read by the /etc/profile shell script to generate the PATH environment variable.

1 Answer 1

6

The /usr/local/sbin directory does not exist on a default macOS installation, but you can easily add it yourself.

To add that directory to the system-wide PATH environment variable (for all users), as there is always the risk of a macOS update overwriting /etc/paths, it might be better to add a file named usr_local_sbin (or anything else) to /etc/paths.d with that single line:

/usr/local/sbin

This will put the /usr/local/sbin path in a position close to the end of PATH, which usually (assuming unique command names) is not a problem. If you want to have it early in PATH for whatever reason, either add to /etc/paths nevertheless or edit the PATH order in the user-specific ~/.profile.

2
  • Comments are not for extended discussions, they have been moved to chat.
    – nohillside
    Jan 2, 2018 at 9:49
  • "Edit the PATH order in the user-specific profile" — Here's a one-liner you can put anywhere in .profile (or .zprofile or .zshrc in modern versions of macOS if you haven't changed your default shell to Bash) to do just that, inserting /usr/local/sbin between /bin and /usr/sbin: PATH="$(echo $PATH | sed -E 's#(^.*:/bin):(/usr/sbin:.*$)#\1:/usr/local/sbin:\2#')"
    – Jivan Pal
    Aug 15, 2022 at 13:33

You must log in to answer this question.

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