If you've installed Cairo via Homebrew (brew install cairo) but your scripts still can't find it, you may need to create symlinks in /usr/local/lib. This is because /usr/local/lib is always searched by macOS and is not blocked by SIP (System Integrity Protection).
-
Create the directory if it doesn't exist:
sudo mkdir -p /usr/local/lib
-
Navigate to
/usr/local/lib:cd /usr/local/lib -
Create symlinks to the Homebrew-installed Cairo library:
sudo ln -sf /opt/homebrew/lib/libcairo.2.dylib libcairo.2.dylib sudo ln -sf /opt/homebrew/lib/libcairo.2.dylib libcairo.dylib sudo ln -sf /opt/homebrew/lib/libcairo.2.dylib libcairo.so.2 sudo ln -sf /opt/homebrew/lib/libcairo.2.dylib libcairo-2.dylib
Some software expects Cairo libraries in /usr/local/lib. Homebrew installs them in /opt/homebrew/lib on Apple Silicon Macs, so symlinking resolves the issue.
Add these lines to your .zshenv to help your system locate the libraries:
export DYLD_FALLBACK_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_FALLBACK_LIBRARY_PATH"
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"
export BREW_LIB='/opt/homebrew/lib'
export DYLD_LIBRARY_PATH=$BREW_LIB:$DYLD_LIBRARY_PATHOn solution that is not yet tested but could work is to place brew first in the PATH add this to the end of your zshrc
export PATH="/opt/homebrew/bin:$PATH"https://jonathansoma.com/everything/blog/2022/solution-to-no-library-called-cairo-2-was-found-error/