pkg-config won't run

I'm trying to fix a path-related problem with glib, but as part of this another problem has appeared:

brew install pkg-config
Warning: pkg-config 0.29.2 is already installed and up-to-date

Ok, good, so:

pkg-config --cflags glib-2.0
-bash: /usr/local/bin/pkg-config: Permission denied

Right, right...

sudo pkg-config --cflags glib-2.0
sudo: pkg-config: command not found

Does anyone know what's going on here?

Update: one of the commands fixed things:

pkg-config --cflags glib-2.0
-I/usr/local/Cellar/glib/2.62.3/include/glib-2.0 -I/usr/local/Cellar/glib/2.62.3/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.43/include

Solution 1:

I wouldn’t sudo anything brew related for installs in /usr/local and use one Unix user only to manage homebrew. The only exception is some initial setup or remediation steps when you are explicitly instructed by the tool to use sudo

What’s happening is some permissions (using sudo likely) went bad in /usr/local so you might need to revert them.

brew doctor

The above command is designed to find and help you fix many of the common ways people can have issues installing packages so I would start there. Also run a command to see what leaves you need in case you have to clean up and remove all the brewed items and reinstall one by one once your permissions are set.

brew leaves