Global Homebrew PATH Prefix for macOS

Based on Homebrew’s FAQ you can set prefix in PATH for all GUI apps which is not enabled by default:

user$ sudo launchctl config user path "$(brew --prefix)/bin:${PATH}"
Configuration applied. You must reboot for changes to take effect.

According to this answer. The sudo launchctl config user path <...> command updates /private/var/db/com.apple.xpc.launchd/config/user.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>PathEnvironmentVariable</key>
	<string>/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
</plist>

You can query launchd‘s current settings via:

launchctl getenv PATH

Related: You can also query the default PATH by executing:

sysctl user.cs_path

Test script with clear environment:

env -i git commit

Leave a Reply

Your email address will not be published.