MacOS – How to revert launchctl PATH to defaults

launchdmacbook promacospathterminal

There are many questions and commentary about using launchctl setenv PATH /path/to/include in order to have GUI apps inherit user-specified paths. I did this about four years ago, and the changes I added have persisted to 10.11.6 (current OS). Unfortunately for me, I have long forgotten these settings until recently…

None of the man pages or commentary indicates how to revert these changes to factory defaults. For instance, running launchctl getenv PATH yields:

/usr/local/bin:/usr/local/opt/libpcap/bin:/usr/local/opt/e2fsprogs/sbin:/usr/local/opt/e2fsprogs/bin:/usr/local/opt/flex/bin:/usr/local/opt/gettext/bin:/usr/local/opt/openssl@1.1/bin:/usr/local/opt/openssl/bin:/usr/local/opt/qt/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/GDAL.framework/Versions/2.1/Programs:/Library/Python/2.7/site-packages:/usr/local/lib/python2.7/site-packages:/Applications/Wireshark.app/Contents/MacOS

Running launchctl setenv PATH [blank] is evidently an error, demanding a non-blank value. I'm also hesitant to experiment with this much because I don't know whether there is a macOS default setting for this key-value pair.

Can someone please tell me how I can flush the current contents of launchctl getenv PATH or to return its content to what would appear in a fresh install? I would rather not replace what's currently there with the default paths from /etc/profile and the like, unless those are the self-same values that appear when running launchctl getenv PATH on a fresh installation.

Edit

Running launchctl unsetenv PATH did clear out the variable, but it did not persist after reboot – i.e., the same path values returned after a restart.

Best Answer

What ended up working to restore to default "factory presets" for me was to run:

sudo launchctl config user path /usr/bin:/bin:/usr/sbin:/sbin

This is not unlike the advice seen here (Set PATH variable so that it is detected in all applications, even outside terminal. (El Captain)). But some lingering questions remain:

  1. Does this procedure restore what was already in the key-value pair of user path, or does it enact a new setting that would otherwise be empty?
  2. Where, i.e., in what file or database, is this key-value stored?