Brew gcc does not install properly

Trying to brew install gcc but gives errors.
Using macOS Catalina 10.15.4

Here’s the bash log:
https://controlc.com/364eac66

Your directory permissions are odd, and it seems that you uninstalled some parts needed for homebrew. To fix the last error you can run sudo chmod -R $(whoami) /usr/local/*.

That fails:

sudo chmod -R $(whoami) /usr/local/*
chmod: Invalid file mode: grek4

What I had to do was:

sudo chown -R $(whoami) /usr/local/*

Keeps failing anyway:

Workstation:~ grek4$ brew install gcc
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
ghz                                                                                     lizard-analyzer                                                                         rbtools
==> Updated Formulae
ammonite-repl         bazel                 ctl                   embree                gatsby-cli            highlight             imgproxy              mono                  opencv                openexr               rawtoaces             synfig
angular-cli           caffe                 dmd                   exploitdb             grpcurl               ilmbase               lcm                   nats-server           opencv@2              openimageio           singular              tor
ask-cli               contentful-cli        easy-tag              flow                  gucharmap             imagemagick           mesa                  nift                  opencv@3              openvdb               starship              vips

Warning: gcc 9.3.0_1 is already installed, it's just not linked
You can use `brew link gcc` to link this version.

Workstation:~ grek4$ brew link gcc
Linking /usr/local/Cellar/gcc/9.3.0_1... 
Error: Could not symlink include/c++
/usr/local/include is not writable.

Workstation:~ grek4$ sudo brew link gcc
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

What does ls -al /usr/local/ say?

Workstation:~ grek4$ ls -al /usr/local/
total 0
drwxr-xr-x  11 root    wheel  352 Apr  9 17:17 .
drwxr-xr-x@ 11 root    wheel  352 Oct 13  2019 ..
-rw-r--r--   1 root    wheel    0 Oct 13  2019 .com.apple.installer.keep
drwxrwxr-x   9 grek4   admin  288 May 14 14:42 Cellar
drwxrwxr-x  21 grek4   admin  672 May 15 11:25 Homebrew
drwxrwxr-x  13 grek4   admin  416 May 15 11:26 bin
drwxrwxr-x   5 grek4   admin  160 May 14 14:41 etc
drwxrwxr-x  10 grek4   admin  320 May 15 11:26 opt
drwxrwxr-x   4 grek4   admin  128 May 14 14:41 sbin
drwxrwxr-x   7 grek4   admin  224 May 14 14:41 share
drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 var

Well, finally bypassed the issue by totally removing brew.sh and reinstalling, however it’s a workaround. The issue is still present to those that want to update having already brew.sh/software installed. Apparently there are interferences or misconfigurations carried from older versions, either of macOS or homebrew itself.

Uninstall homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

Remove everything:

sudo su
cd /usr/local/
rm -r *
exit

Reinstall homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Install desired package:

brew install gcc

In case you want me to continue debugging the issue with update over existing installation, just say it. Obviously it’s a bug which shouldn’t be there, updating should take into consideration existing install.

you’re missing the include directory somehow, creating it should fix your issye but I’d recommend figuring out how it went missing in the first place

The issue may have been caused by either a previous install of brew or by macOS update/upgrade. I’m running 10.15.4 on a virtual machine for testing, but don’t remember exactly when was the first time brew was installed. Maybe 10.12 or 10.13 but didn’t pay much attention to it. Does brew keep an history record of all the updates versions /timestamps /formulae install uninstall update? I don’t see how I could debug this issue other than that. I don’t recall manually touching the /usr/local/ directory.

It doesn’t keep such records but formulae don’t have permission to change those directories so that’s not the problem.

But does brew change those directories or not? formulare already see that not.

Brew will never remove directories it depends on.

Ok, but then who should provide /urs/local/include/, macOS standard installation, Xcode, command line tools, brew…?

The homebrew install script creates it and nothing else is supposed to touch it (and nothing in the brew ecosystem will ever remove it).

So only the script to remove brew will touch it, no formulae install/uninstall could do that? What happens if there’s a bug in some formulae?
My only guess then is that it was any macOS upgrade. From now on with each brew command you should check for those directories.

If there’s a bug in a formula they only write or delete in /usr/local/Cellar. The other directories only contain symlinks.
As for macOS upgrades, Apple has left that directory untouched for 10+ years IIRC. I think this is a case of operator error.

brew doctor will check for these directories, we don’t run status checks on every command.

This is how it looks like on each macOS version, as it was exactly back in the day. Each newer version has been OS upgrade over existing version, using official Apple updater from Apple Store.


  • macOS 10.13 // fresh install
sw_vers
ProductName:	Mac OS X
ProductVersion:	10.13
BuildVersion:	17A365

brew
-bash: brew: command not found

ls -lsa /usr/local/
total 0
0 drwxr-xr-x  3 root  wheel  102 Sep 27  2017 .
0 drwxr-xr-x@ 9 root  wheel  306 Sep 20  2017 ..
0 -rw-r--r--  1 root  wheel    0 Sep 27  2017 .com.apple.installer.keep

  • macOS 10.13.6
sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G8037

brew -v
Homebrew 1.6.6
Homebrew/homebrew-core (git revision 28d4; last commit 2018-05-25)

brew list
star

brew info
1 keg, 87 files, 1.5MB

ls -lsa /usr/local/
total 0
0 drwxr-xr-x  14 root    wheel  476 May 25  2018 .
0 drwxr-xr-x@ 10 root    wheel  340 Oct 21  2017 ..
0 -rw-r--r--   1 root    wheel    0 Oct 13  2019 .com.apple.installer.keep
0 drwxrwxr-x   3 grek4   admin  102 May 25  2018 Cellar
0 drwxrwxr-x   2 grek4   admin   68 May 25  2018 Frameworks
0 drwxrwxr-x  17 grek4   admin  578 May 25  2018 Homebrew
0 drwxrwxr-x  12 grek4   admin  408 May 25  2018 bin
0 drwxrwxr-x   4 grek4   admin  136 May 25  2018 etc
0 drwxrwxr-x   2 grek4   admin   68 May 25  2018 include
0 drwxrwxr-x   2 grek4   admin   68 May 25  2018 lib
0 drwxrwxr-x   3 grek4   admin  102 May 25  2018 opt
0 drwxrwxr-x   3 grek4   admin  102 May 25  2018 sbin
0 drwxrwxr-x   5 grek4   admin  170 May 25  2018 share
0 drwxrwxr-x   3 grek4   admin  102 May 25  2018 var

ls -lsa /usr/local/include/
total 0
0 drwxrwxr-x   2 grek4   admin   68 May 25  2018 .
0 drwxr-xr-x  14 root    wheel  476 May 25  2018 ..

brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Ruby version 2.3.7 is unsupported on 10.13. Homebrew
is developed and tested on Ruby 2.3.3, and may not work correctly
on other Rubies. Patches are accepted as long as they don't cause breakage
on supported Rubies.

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
  echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile

  • macOS 10.14.6
sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G103

brew -v
Homebrew >=1.4.0 (shallow or no git repository)
Homebrew/homebrew-core (no git repository)

brew list
star

brew info
1 keg, 87 files, 1.5MB

ls -lsa /usr/local/
total 0
0 drwxr-xr-x  11 root    wheel  352 Oct 13  2019 .
0 drwxr-xr-x@  9 root    wheel  288 Sep 20  2018 ..
0 -rw-r--r--   1 root    wheel    0 Oct 13  2019 .com.apple.installer.keep
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 Cellar
0 drwxrwxr-x  17 grek4   admin  544 Oct 13  2019 Homebrew
0 drwxrwxr-x  12 grek4   admin  384 Oct 13  2019 bin
0 drwxrwxr-x   4 grek4   admin  128 Oct 13  2019 etc
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 opt
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 sbin
0 drwxrwxr-x   5 grek4   admin  160 Oct 13  2019 share
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 var

brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git
checkouts instead of stable tarballs. You may want to install Git:
  brew install git

Warning: No developer tools installed.
Install the Command Line Tools:
  xcode-select --install


Warning: You are using macOS 10.14.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.

Warning: Ruby version 2.3.7 is unsupported on 10.14. Homebrew
is developed and tested on Ruby 2.3.3, and may not work correctly
on other Rubies. Patches are accepted as long as they don't cause breakage
on supported Rubies.

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
  echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile

  • macOS 10.15.4
sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.15.4
BuildVersion:	19E287

brew -v
Homebrew >=1.4.0 (shallow or no git repository)
Homebrew/homebrew-core (no git repository)

brew list
star

brew info
1 keg, 87 files, 1.5MB

ls -lsa /usr/local/
total 0
0 drwxr-xr-x  11 root    wheel  352 Apr  9 17:17 .
0 drwxr-xr-x@ 11 root    wheel  352 Oct 13  2019 ..
0 -rw-r--r--   1 root    wheel    0 Oct 13  2019 .com.apple.installer.keep
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 Cellar
0 drwxrwxr-x  17 grek4   admin  544 Oct 13  2019 Homebrew
0 drwxrwxr-x  12 grek4   admin  384 Oct 13  2019 bin
0 drwxrwxr-x   4 grek4   admin  128 Oct 13  2019 etc
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 opt
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 sbin
0 drwxrwxr-x   5 grek4   admin  160 Oct 13  2019 share
0 drwxrwxr-x   3 grek4   admin   96 Oct 13  2019 var

brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git
checkouts instead of stable tarballs. You may want to install Git:
  brew install git

Warning: No developer tools installed.
Install the Command Line Tools:
  xcode-select --install


Warning: You are using macOS 10.15.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.

Warning: Ruby version 2.6.3 is unsupported on 10.15. Homebrew
is developed and tested on Ruby 2.3.3, and may not work correctly
on other Rubies. Patches are accepted as long as they don't cause breakage
on supported Rubies.

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
  echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile

  • macOS 10.15.4. // after full delete and reinstall of brew
sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.15.4
BuildVersion:	19E287

brew -v
Homebrew 2.2.17
Homebrew/homebrew-core (git revision 20d2a8; last commit 2020-05-19)

brew list
gcc		glew		glfw		gmp		isl		jq		libmpc		libusb		make		mingw-w64	mpfr		oniguruma	pkg-config	sdl2

brew info
14 kegs, 9,489 files, 1.1GB

ls -lsa /usr/local/
total 0
0 drwxr-xr-x  15 root    wheel   480 May 17 09:46 .
0 drwxr-xr-x@ 11 root    wheel   352 Oct 13  2019 ..
0 -rw-r--r--   1 root    wheel     0 Oct 13  2019 .com.apple.installer.keep
0 drwxrwxr-x   2 grek4   admin    64 May 17 09:46 Caskroom
0 drwxrwxr-x  17 grek4   admin   544 May 19 17:23 Cellar
0 drwxrwxr-x   3 grek4   admin    96 May 17 09:51 Frameworks
0 drwxrwxr-x  20 grek4   admin   640 May 19 17:22 Homebrew
0 drwxrwxr-x  95 grek4   admin  3040 May 19 17:23 bin
0 drwxrwxr-x   4 grek4   admin   128 May 17 09:51 etc
0 drwxrwxr-x  19 grek4   admin   608 May 19 17:23 include
0 drwxrwxr-x  42 grek4   admin  1344 May 19 17:23 lib
0 drwxrwxr-x  19 grek4   admin   608 May 19 17:23 opt
0 drwxrwxr-x   3 grek4   admin    96 May 17 09:51 sbin
0 drwxrwxr-x  12 grek4   admin   384 May 17 20:35 share
0 drwxrwxr-x   3 grek4   admin    96 May 17 09:46 var

ls -lsa /usr/local/include/
total 0
0 drwxrwxr-x  19 grek4   admin  608 May 19 17:23 .
0 drwxr-xr-x  15 root    wheel  480 May 17 09:46 ..
0 -rw-r--r--   1 grek4   admin    0 May 17 09:51 .keepme
0 lrwxr-xr-x   1 grek4   admin   33 May 17 20:26 GL -> ../Cellar/glew/2.1.0_1/include/GL
0 lrwxr-xr-x   1 grek4   admin   33 May 17 20:30 GLFW -> ../Cellar/glfw/3.3.2/include/GLFW
0 lrwxr-xr-x   1 grek4   admin   36 May 17 20:19 SDL2 -> ../Cellar/sdl2/2.0.12_1/include/SDL2
0 lrwxr-xr-x   1 grek4   admin   33 May 17 20:18 c++ -> ../Cellar/gcc/9.3.0_1/include/c++
0 lrwxr-xr-x   1 grek4   admin   33 May 17 20:14 gmp.h -> ../Cellar/gmp/6.2.0/include/gmp.h
0 lrwxr-xr-x   1 grek4   admin   35 May 17 20:14 gmpxx.h -> ../Cellar/gmp/6.2.0/include/gmpxx.h
0 lrwxr-xr-x   1 grek4   admin   36 May 17 20:14 gnumake.h -> ../Cellar/make/4.3/include/gnumake.h
0 lrwxr-xr-x   1 grek4   admin   32 May 17 20:14 isl -> ../Cellar/isl/0.22.1/include/isl
0 lrwxr-xr-x   1 grek4   admin   29 May 19 17:23 jq.h -> ../Cellar/jq/1.6/include/jq.h
0 lrwxr-xr-x   1 grek4   admin   29 May 19 17:23 jv.h -> ../Cellar/jq/1.6/include/jv.h
0 lrwxr-xr-x   1 grek4   admin   42 May 17 20:35 libusb-1.0 -> ../Cellar/libusb/1.0.23/include/libusb-1.0
0 lrwxr-xr-x   1 grek4   admin   36 May 17 20:14 mpc.h -> ../Cellar/libmpc/1.1.0/include/mpc.h
0 lrwxr-xr-x   1 grek4   admin   39 May 17 20:14 mpf2mpfr.h -> ../Cellar/mpfr/4.0.2/include/mpf2mpfr.h
0 lrwxr-xr-x   1 grek4   admin   35 May 17 20:14 mpfr.h -> ../Cellar/mpfr/4.0.2/include/mpfr.h
0 lrwxr-xr-x   1 grek4   admin   48 May 19 17:23 oniggnu.h -> ../Cellar/oniguruma/6.9.5-rev1/include/oniggnu.h
0 lrwxr-xr-x   1 grek4   admin   50 May 19 17:23 oniguruma.h -> ../Cellar/oniguruma/6.9.5-rev1/include/oniguruma.h

brew doctor
Your system is ready to brew.