How to remove a service from launchd added by mistake? By mistake I added an invalid (non-existing) service to launchd:

sudo launchctl enable system/homebew.mxcl.cntlm


The above should be system/homebrew.mxcl.cntlm instead.

However, after removing the service:

sudo launchctl remove system/homebew.mxcl.cntlm


it still shows in the list of disabled services:

nlykkei-mbp:~ nlykkei$ launchctl print-disabled system
disabled services = {
    "org.apache.http" =&gt; false
    "homebrew.mxcl.dnsmasq" =&gt; false
    "com.apple.CSCSupportd" =&gt; true
    "com.apple.ftpd" =&gt; true
    "com.apple.mdmclient.daemon.runatboot" =&gt; true
    "com.openssh.sshd" =&gt; false
    "org.apache.httpd" =&gt; true
    "com.apple.bootpd" =&gt; true
    "homebrew.mxcl.cntlm" =&gt; false
    "org.macosforge.xquartz.privileged_startx" =&gt; false
    "com.launchd.maxfiles" =&gt; false
    "com.apple.ftp-proxy" =&gt; true
    "homebew.mxcl.cntlm" =&gt; false     &lt;-- doesn't exist
}


How can I remove all traces of homebew.mxcl.cntlm from my system, so that it doesn't show up using launchctl?
Immediately after removing the service you won't be able to find the service name in a distinctive and editable file. It's probably hidden in some cache.

After a reboot you should be able to remove its traces by performing these steps though:


Search for the name of the non-existent service to remove in the files of this directory: /var/db/com.apple.xpc.launchd

sudo grep -rnw '/var/db/com.apple.xpc.launchd/' -e "homebew"

Edit the file found by grep with nano (the string is probably found in disabled.plist)

sudo nano /var/db/com.apple.xpc.launchd/disabled.plist


Move the cursor to the two incriminating lines (service name e.g. &lt;key&gt;homebew.mxcl.cntlm&lt;/key&gt; followed by its status e.g. &lt;false/&gt;) and remove each with ctrlK. Hit ctrlO, ⏎ and ctrlX, ⏎ to save the changes to disk and leave nano.
Reboot again and launchctl print-disabled system won't show the service anymore.




Due to an agressive caching mechanism or other opaque system procedures, removing the lines doesn't work reliably with vim or nano (on the OP's system it didn't work at all, in my Catalina VM 5 out of 6 attempts have been successful).

Then the file has to be cleaned in Recovery Mode:


Boot to Recovery Mode
In the menubar open Terminal
Edit the file with nano. The paths depend on your main volume name (e.g. Macintosh HD):

/Volumes/Macintosh\ HD/usr/bin/nano /Volumes/Macintosh\ HD//var/db/com.apple.xpc.launchd/disabled.plist

Enter reboot to boot normally.