Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does launchctl config user path do?

I was having a strange problem with PATH environment variable in MacOS that I spent several hours to debug:

  • Some time ago, when I was trying to fix the issue IntelliJ terminal PATH variable not the same with iTerm, I followed an online article and executed this:

    sudo launchctl config user path $PATH

  • Apparently this command sets and persists the value of PATH variable at that moment of time somewhere and that variable is loaded even before my shell is loaded whenever I start a new zsh session. Only recently I recognized this issue because I removed some paths location setting in my zshrc and the PATH variable still didn't reflect

  • My question is where does that command store the PATH variable value? and how does it load that value before my shell is loaded?

(For people who wonder how I fixed the issue: I executed the command again to set path to empty value: sudo launchctl config user path '')

like image 338
Phuong Nguyen Avatar asked Aug 01 '18 14:08

Phuong Nguyen


1 Answers

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

$ cat /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>

Tested on my system, which is currently macOS 12.1 (AppleSilicon). You can replace user with system to operate on the system-wide preferences. Both require sudo, oddly enough.

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
like image 134
luckman212 Avatar answered Nov 13 '22 19:11

luckman212