Fix Homebrew 'Permission denied @ apply2files' error

By

How to fix the Homebrew Permission denied @ apply2files error during brew cleanup by recreating the missing folder, like the Docker cli-plugins directory.

~~~

The Permission denied @ apply2files error shows up when brew cleanup hits a file it can’t process. In my case the cause was a folder full of broken symbolic links, left behind by an app I had deleted. Recreating the folder those links pointed to fixed it.

Here’s the full story.

After running brew upgrade node to upgrade my Node.js installation on macOS, Homebrew decided to run brew cleanup automatically.

It was doing its things, with a bunch of Removing: /Users/..... lines, until I got the error:

Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins

🤔

See “docker” in the path?

What caused it

Turns out I had deleted Docker recently.

The /usr/local/lib/docker/cli-plugins folder contains symbolic links that point inside the Docker app, in /Applications. With the app gone, those links pointed to nothing, and brew cleanup errored out when it reached them.

The fix

What I did to fix was to recreate the folder of the Docker app the links pointed to:

mkdir -p /Applications/Docker.app/Contents/Resources/cli-plugins

and running

brew cleanup

Again. The issue was fixed.

If you removed Docker for good and you don’t plan to reinstall it, you can delete the leftover folder instead of recreating the target:

sudo rm -rf /usr/local/lib/docker

Either way, brew cleanup stops complaining because the broken links are gone or resolved.

What if your path is different?

The path in the error message tells you which tool left files behind. It might be Docker like in my case, or another app entirely.

Sometimes it’s a plain ownership problem: the file exists, but it belongs to root, so Homebrew can’t touch it. You can give it back to your user:

sudo chown -R $(whoami) /usr/local/lib/docker

Replace the path with the one from your error message.

Your issue might be caused by another library missing, not Docker, so in this case you can Google the specific error message you have and see if someone else had the same issue and figured it out. But that’s a start.

One thing you should not do: run sudo brew cleanup. Homebrew refuses to run as root, and for good reason. Fix the ownership of the specific path instead of forcing the whole command.

Tagged: Node.js · All topics
~~~

Related posts about node: