path_helper

Wie kommt unter macOS eigentlich der $PATH zustande?

Die /etc/profile führt beim Start den path_helper aus:

cat /etc/profile
# System-wide .profile for sh(1)

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

man path_helper spricht folgendes:

  • $PATH wird zusammengesetzt aus folgenden Dateien:
    • /etc/paths und alles unter /etc/paths.d/
  • Eine Zeile == ein Ordner
  • … should not be invoked directly
    • It is intended only for use by the shell profile.

Also: Dort ansetzen:

echo "/Users/user/bin" > /etc/paths.d/user

Schaut dann so aus:

ls /etc/paths.d
MacGPG2    TeX        user
cat /etc/paths.d/*
/usr/local/MacGPG2/bin
/Library/TeX/texbin
/Users/user/bin
cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Funktioniert für alle Shells.

Obacht: /Users/user/bin gilt dann für alle Benutzer.

Der Check gibt folgendes:

/usr/libexec/path_helper -s
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/user/bin:/Library/TeX/texbin:/usr/local/MacGPG2/bin"; export PATH;