How I fixed an "Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins" error

The error is due to broken permissions

🖥️
Homebrew version: 6.6.17
macOS version: Ventura 13.0.1
Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins

This error was related to brew on macOS. I got it while running brew cleanup. I uninstalled the Docker app a few days ago. I don't remember how I installed the Docker app, but it's not impossible that I installed Docker via Homebrew but uninstalled it via the app itself. Hence, the error — even though it's mere speculation.

I searched the error on DuckDuckGo and found two fixes. The first one was to recreate the missing file — as explained here, for instance. I wasn't comfortable using it, as I deleted Docker and don't want to recreate files for an app that doesn't exist anymore on my system.

I found another fix, first on StackOverflow, but it references a discussion on GitHub:

sudo chown -R $(whoami):admin /usr/local/* \
&& sudo chmod -R g+rwx /usr/local/*

Apparently, something related with permissions was broken. This shell command restored them to a working state.

brew doctor ran without error after this!