Search code examples
pythonhomebrewpermission-deniedmacos-mojave

Unable to brew upgrade Python in Mojave


I ran brew outdated in macOS Mojave 10.14.2 and determined that python and python@2 were outdated. When I ran brew upgrade it failed for both. For example for python@2:

==> Upgrading python@2 
==> Downloading https://homebrew.bintray.com/bottles/[email protected]_2.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring [email protected]_2.mojave.bottle.tar.gz
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

I ran brew doctor and it recommends to brew link but this still fails with the same permission error:

Linking /usr/local/Cellar/python@2/2.7.15_2... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

This post recommends to grant privileges to the parent directory, but I want to understand why this happens and find a solution for learning.


Solution

  • I found the answer here. I had to sudo mkdir /usr/local/Frameworks to create the missing directory first, then sudo chown -R $(whoami) $(brew --prefix)/* since sudo chown -R $(whoami) /usr/local no longer works in Mojave - and High Sierra before that, according to the post. I was able to brew link python and brew link python@2 after that.