I ran the following command
php -v, and instead of getting the version, I got the following error:
dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib Referenced from: /usr/local/bin/php Reason: image not found
I tried many things I found online, but the following is what did the trick for me.
How to fix the error
brew update. For me, everything was up to date.
I got the following error:
Removing: /usr/local/Cellar/php/7.4.4... (517 files, 76MB) Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/php/7.4.4
brew cleanup, and I got a similar error:
Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/nginx/1.17.9
sudo rm -R /usr/local/Cellar/nginx/1.17.9.
brew cleanupagain, and once again, I got a similar error.
Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/php/7.4.4
This is the same error as my step 2.
sudo rm -R /usr/local/Cellar/php/7.4.4.
I then ran
brew cleanupagain. It seemed like everything worked.
Pruned 0 symbolic links and 15 directories from /usr/local
Finally, I tried
php -vagain, and this time it worked!
If you are getting a “dyld: Library not loaded > Reason: image not found” error, try running
brew update and
brew upgrade. If you get a
Error: Directory not empty, try removing that directory using
sudo rm -R.