# Installing older version gcc@9.3.0 using brew?

Gold Member
I'd like to install gcc version 9.3.0 on my Mac Os Big Sur. I was wondering if I can do this still using brew?

I already have the most up to date version of brew but I would like to possibly downgrade or have in addition gcc v9.3.0.

I followed the three commands below

brew tap-new $USER/local-gcc brew extract --version=9.3.0 gcc$USER/local-gcc

brew install gcc@9.3.0

but when I do

brew info gcc

it still says I have v10.2.0. Is there a way to switch between different versions? As far as I can tell brew switch is now broken.

If there is another way to get a working gcc v 9.3.0 that you can recommend I am happy to try it too. Thanks in advance.

Gold Member
2022 Award
Probably you posted this same question at Stack Overflow as well, right?

First check if brew list --versions gcc returns the old version. If it does, then probably you can use brew switch gcc 9.3.0 to go to the old version and use it.

If it doesn't return the old version, we have to think of something else.

N.B.: I do not have a PC running macOS, so all my help will be based on the internet.

CAF123
Gold Member
Hi @Wrichik Basu
Probably you posted this same question at Stack Overflow as well, right?
Yes
First check if brew list --versions gcc returns the old version. If it does, then probably you can use brew switch gcc 9.3.0 to go to the old version and use it.
brew list --versions gcc returns gcc 10.2.0_4 however brew list --versions gcc@9 returns gcc@9 9.3.0_1. Also, as far as I know, now  brew switch  is obsolete.

N.B.: I do not have a PC running macOS, so all my help will be based on the internet.
I see, thanks.

Staff Emeritus
Homework Helper
I ran across a question about using different versions of Python, and someone replied telling the user to use brew link. I've never used Homebrew (or at least it's been so long I don't remember trying it out), so it might be a completely useless suggestion.

CAF123
Gold Member
Hi @vela
I ran across a question about using different versions of Python, and someone replied telling the user to use brew link. I've never used Homebrew (or at least it's been so long I don't remember trying it out), so it might be a completely useless suggestion.
Thanks, I had tried  brew link gcc@9  and it says  Already linked: /usr/local/Cellar/gcc@9/9.3.0_1. I have never symlinked before so not sure if I am using brew link in the correct way here. Do you know?

Also, a little bit more broadly, why doesn't adding the explicit path of my gcc@9 to my .zshrc work? E.g. adding
 export PATH=$PATH:/usr/local/Cellar/gcc@9/9.3.0_1 to the top of the shell? Staff Emeritus Science Advisor Homework Helper Education Advisor Thanks, I had tried  brew link gcc@9  and it says  Already linked: /usr/local/Cellar/gcc@9/9.3.0_1. I have never symlinked before so not sure if I am using brew link in the correct way here. Do you know? It sounds like it, but I'm pretty ignorant about Homebrew. Also, a little bit more broadly, why doesn't adding the explicit path of my gcc@9 to my .zshrc work? E.g. adding export PATH=$PATH:/usr/local/Cellar/gcc@9/9.3.0_1 to the top of the shell?
Because you're adding the directory to the end of the path, that's the last place the system will look for gcc. You could try tacking it on the front instead.

The command which gcc will tell you which gcc the system will use by default.

CAF123
Gold Member
Thanks.
Because you're adding the directory to the end of the path, that's the last place the system will look for gcc. You could try tacking it on the front instead.
I didn't quite understand what you meant by 'tacking it on the front instead'. Could you explain a bit more there?

The command which gcc will tell you which gcc the system will use by default.
which gcc returns /usr/bin/gcc and which gcc@9 returns  gcc@9 not found . Seems strange given e.g. the output of  brew ls --versions gcc@9  in #3 but maybe I'm being naive.

Staff Emeritus
Homework Helper
I didn't quite understand what you meant by 'tacking it on the front instead'. Could you explain a bit more there?
If PATH is set to, say, "directory 1:directory 2", the system first searches directory 1 for the program you're trying to run, and if it can't find it there, it then looks in directory 2. Because you added the gcc9 directory to the end, that's the last place the system will look for gcc. To make it the first place it looks, put it at the beginning of PATH. That said, you probably shouldn't add that directory, which likely contains a lot of other stuff, to PATH.

What is your PATH variable set to? I'm using MacPorts, and I'm pretty sure on installation that it added /opt/local/bin and /opt/local/sbin, which are where it places executables, to PATH. I'd guess Homebrew does something similar.

If you were to look in /opt/local/bin (or whatever the corresponding directory for Homebrew is), you should find an executable or symbolic link called gcc. Try checking the version of that to see which one is installed by Homebrew.
which gcc returns /usr/bin/gcc and which gcc@9 returns  gcc@9 not found . Seems strange given e.g. the output of  brew ls --versions gcc@9  in #3 but maybe I'm being naive.
I'm pretty sure the older version of gcc creates an executable called gcc, not gcc@9.

Last edited:
CAF123
Gold Member
Thanks, in /usr/local/opt I find gcc, gcc@10, gcc@9 while in /usr/local/bin I find gcc-10 and gcc-9. I think the former are symbolic links and the latter are the executable files (following https://mkyong.com/mac/where-does-homebrew-install-packages-on-mac/). I'm just not really clear on how to tell the system to use compiler gcc-9 rather than I guess gcc or gcc-10 that it is using now.

Staff Emeritus
Homework Helper
Please show show us the output of
• ls -l /usr/local/bin/gcc*
• ls -l /usr/local/opt/gcc*
• echo $PATH Gold Member Thanks, see below for the various outputs, ls -l /usr/local/bin/gcc* lrwxr-xr-x 1 <me> admin 33 Mar 9 14:58 /usr/local/bin/gcc-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-10 lrwxr-xr-x 1 <me> admin 33 Mar 2 09:52 /usr/local/bin/gcc-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-9 lrwxr-xr-x 1 <me> admin 36 Mar 9 14:58 /usr/local/bin/gcc-ar-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-ar-10 lrwxr-xr-x 1 <me> admin 36 Mar 2 09:52 /usr/local/bin/gcc-ar-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-ar-9 lrwxr-xr-x 1 <me> admin 36 Mar 9 14:58 /usr/local/bin/gcc-nm-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-nm-10 lrwxr-xr-x 1 <me> admin 36 Mar 2 09:52 /usr/local/bin/gcc-nm-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-nm-9 lrwxr-xr-x 1 <me> admin 40 Mar 9 14:58 /usr/local/bin/gcc-ranlib-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-ranlib-10 lrwxr-xr-x 1 <me> admin 40 Mar 2 09:52 /usr/local/bin/gcc-ranlib-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-ranlib-9 ls -l /usr/local/opt/gcc* lrwxr-xr-x 1 <me> admin 22 Mar 9 14:58 /usr/local/opt/gcc -> ../Cellar/gcc/10.2.0_4 lrwxr-xr-x 1 <me> admin 22 Mar 9 14:58 /usr/local/opt/gcc@10 -> ../Cellar/gcc/10.2.0_4 lrwxr-xr-x 1 <me> admin 23 Mar 2 09:52 /usr/local/opt/gcc@9 -> ../Cellar/gcc@9/9.3.0_1 lrwxr-xr-x 1 <me> admin 27 Mar 2 10:37 /usr/local/opt/gcc@9.3.0 -> ../Cellar/gcc@9.3.0/9.3.0_1 echo$PATH

/usr/local/opt/gnu-tar/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/bin/gcc-9:/usr/local/Cellar/gcc@9/:/usr/local/Cellar:/usr/local/bin/gfortran:/usr/local/bin

Staff Emeritus
Homework Helper
Use gcc-9 to run the older version and gcc-10 to run the newer version. Plain old gcc will run the compiler that comes with Xcode.

You should probably remove /usr/local/bin/gcc-9, /usr/local/Cellar/gcc@9/, and /usr/local/Cellar from PATH. You also have /usr/local/bin in there twice, so remove one of them.

CAF123
Gold Member
Thanks very much, yes so gfortran-9 myfile.f, gfortran-10 myfile.f or gfortran myfile.f all respond correctly to a simple Hello World test program while gcc-9 myfile.f, gcc-10 myfile.f or gcc myfile.f do not. Should that be the case?

The software in question that requires v9 of gcc is installed via an installation script by ./ installation_script (along with other dependencies which seem to not require this downgraded version of gcc). As I am only writing in the terminal ./ installation_script, would you know how to modify this command so as to let the script know to use gcc-9?

Staff Emeritus
Homework Helper
Thanks very much, yes so gfortran-9 myfile.f, gfortran-10 myfile.f or gfortran myfile.f all respond correctly to a simple Hello World test program while gcc-9 myfile.f, gcc-10 myfile.f or gcc myfile.f do not. Should that be the case?
I don't know.

The software in question that requires v9 of gcc is installed via an installation script by ./ installation_script (along with other dependencies which seem to not require this downgraded version of gcc). As I am only writing in the terminal ./ installation_script, would you know how to modify this command so as to let the script know to use gcc-9?
It depends. The script might be written so you can somehow specify which gcc to use. If not, it's probably easiest to modify the script so it uses gcc-9, e.g., alias gcc to /usr/local/bin/gcc-9.

CAF123
Gold Member
Thanks, I had tried adding  alias gcc=‘gcc-9’  but it didn't immediately work. Secondly, I had tried a symlink from gcc to gcc-9 via

 ln -sf /usr/local/bin/gcc-9 /usr/local/bin/gcc 

Now,  gcc --version  gives
 gcc (Homebrew GCC 9.3.0_1) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

which is what I want but

 brew ls gcc --version  is still  gcc 10.2.0_4 .

The command you asked for before,  ls -l /usr/local/bin/gcc*  is now

lrwxr-xr-x 1 <me> admin 20 Mar 13 18:46 /usr/local/bin/gcc -> /usr/local/bin/gcc-9
lrwxr-xr-x 1 <me> admin 20 Mar 13 20:54 /usr/local/bin/gcc-10 -> /usr/local/bin/gcc-9
lrwxr-xr-x 1 <me> admin 33 Mar 2 09:52 /usr/local/bin/gcc-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-9
lrwxr-xr-x 1 <me> admin 36 Mar 13 18:10 /usr/local/bin/gcc-ar-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-ar-10
lrwxr-xr-x 1 <me> admin 36 Mar 2 09:52 /usr/local/bin/gcc-ar-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-ar-9
lrwxr-xr-x 1 <me> admin 36 Mar 13 18:10 /usr/local/bin/gcc-nm-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-nm-10
lrwxr-xr-x 1 <me> admin 36 Mar 2 09:52 /usr/local/bin/gcc-nm-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-nm-9
lrwxr-xr-x 1 <me> admin 40 Mar 13 18:10 /usr/local/bin/gcc-ranlib-10 -> ../Cellar/gcc/10.2.0_4/bin/gcc-ranlib-10
lrwxr-xr-x 1 <me> admin 40 Mar 2 09:52 /usr/local/bin/gcc-ranlib-9 -> ../Cellar/gcc@9/9.3.0_1/bin/gcc-ranlib-9

while  ls -l /usr/local/opt/gcc*  is

lrwxr-xr-x 1 <me> admin 22 Mar 13 18:10 /usr/local/opt/gcc -> ../Cellar/gcc/10.2.0_4
lrwxr-xr-x 1 <me> admin 22 Mar 13 18:10 /usr/local/opt/gcc@10 -> ../Cellar/gcc/10.2.0_4
lrwxr-xr-x 1 <me> admin 23 Mar 2 09:52 /usr/local/opt/gcc@9 -> ../Cellar/gcc@9/9.3.0_1
lrwxr-xr-x 1 <me> admin 27 Mar 2 10:37 /usr/local/opt/gcc@9.3.0 -> ../Cellar/gcc@9.3.0/9.3.0_1

So, I can think of two things to try next: make all references of gcc-10 to gcc-9 in the output of  ls -l /usr/local/bin/gcc* ` or/and make /usr/local/opt/gcc -> ../Cellar/gcc/10.2.0_4 instead read /usr/local/opt/gcc -> ../Cellar/gcc@9/9.3.0_1 or something.

I don't have much experience messing with such things and I'm always worried that I do something that messes up the whole system and nothing can compile.