brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a file in /etc/paths.d adds a folder to PATH for every Mac user

Terminal
~/tips/tip-macos-path-helper-paths-d

sudo sh -c 'echo /opt/mytools/bin > /etc/paths.d/mytools'

Adds a folder to the command search path for all users on a Mac.

Editing every user’s dotfiles to add one folder to PATH is no fun. macOS has a tidier spot for it that many people never notice: /etc/paths.d.

The tool behind it is path_helper. Its man page says it first builds a default PATH from /etc/paths, then reads every file in /etc/paths.d and appends their contents, one path element per line. There is a matching /etc/manpaths.d for MANPATH. You never call it yourself; the man page says it is meant to be run only by the shell profile.

So to add a folder for everyone on the Mac, drop a small file in:

sudo sh -c 'echo /opt/mytools/bin > /etc/paths.d/mytools'

Open a new Terminal window and check the result:

echo $PATH | tr ':' '\n'

Your folder should show up near the end of the list. To see what is there already, cat /etc/paths and ls /etc/paths.d are quick reads.

Two caveats. The folders are appended, not prepended, so a command with the same name in one of the default folders from /etc/paths still wins over yours. If you need yours first, set that in your own ~/.zprofile instead. And it only affects new login shells, so a window that was already open keeps its old PATH. Since the file lives in /etc, I’d also keep a note of it: on a new Mac it will not come along unless you bring it.

Further reading: path_helper(8) man page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link