It looks like the install -D command is actually what I want.

Manpage:

-D create all leading components of DEST except the last, then copy SOURCE to DEST

Works great, except you have to specify every file individually.

Answer from ashgromnies on Stack Exchange
🌐
GNU
gcc.gnu.org › install
Installing GCC - GNU Project
The latest version of this document is always available at https://gcc.gnu.org/install/. It refers to the current development sources, instructions for specific released versions are included with the sources.
🌐
nixCraft
cyberciti.biz › nixcraft › howto › linux › ubuntu linux install gnu gcc compiler and development environment
Ubuntu Linux Install GNU GCC Compiler and Development Environment - nixCraft
August 11, 2025 - Explains how to install development tools such as GNU GCC C/C++ compiler and related tools on a Ubuntu Linux using the APT command.
🌐
GNU
gnu.org › software › sourceinstall
GNU Source Installer
It provides configuration, compilation, installation, upgrade, tracking and removal of packages built from source code following the GNU coding standards.
🌐
GNU
gnu.org › software › sourceinstall › article.html
UNIX source installations made easier with GNU Source Installer
The tarball released by the original developers sufficies, provided it honours some de-facto standards about UNIX package installations. GNU Source Installer shows all commands it executes in the background, and comments them, so a new user should be able to slowly notice the patterns which develop during installation, and eventually gain more knowledge and confidence in UNIX commands in general.
🌐
GNU
gnu.org › software › coreutils › manual › html_node › install-invocation.html
install invocation (GNU Coreutils 9.11)
If the --target-directory (-t) option is given, or failing that if the last file is a directory and the --no-target-directory (-T) option is not given, install copies each source file to the specified directory, using the sources’ names.
🌐
SourceForge
sourceforge.net › projects › mingw
MinGW - Minimalist GNU for Windows download | SourceForge.net
Download MinGW - Minimalist GNU for Windows for free. A native Windows port of the GNU Compiler Collection (GCC) MinGW: A native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality.
Rating: 4.3 ​ - ​ 223 votes
Find elsewhere
🌐
IBM
ibm.com › docs › en › devops-test-embedded › 9.0.0
Installing the Recommended GNU Compiler on Windows - IBM Documentation
January 29, 2026 - Since the Tutorial requires access to both a C and C++ compiler, if you are working on a Windows operating system and you do not have Windows Visual C++ 6.0 installed, you are advised to install the following, recommended GNU C and C++ compiler.
🌐
Medium
medium.com › @mikeymop › how-to-setup-a-gnu-development-environment-on-all-platforms-3e37c35c91d7
How to setup a GNU development Environment on all Platforms | by Michael DeFrancesco | Medium
July 19, 2019 - brew install gcc brew install g++ brew install gdb · You can now build and debug your code using the standard GNU Toolchain.
🌐
GNU
gnu.org › software › gnuboot › docs › gnulinux › grub_boot_installer.html
GNU Boot – Installing GNU+Linux
If you downloaded your ISO while on an existing GNU+Linux system, here is how to create the bootable GNU+Linux USB drive: Connect the USB drive. Check lsblk, to confirm its device name (e.g., /dev/sdX): ... For this example, let’s assume that our drive’s name is sdb. Make sure that it’s not mounted: ... Overwrite the drive, writing your distro ISO to it with dd. For example, if we are installing Foobarbaz GNU+Linux, and it’s located in our Downloads folder, this is the command we would run:
🌐
CircleCI
discuss.circleci.com › build environment
How to install latest version of GNU? - Build Environment - CircleCI Discuss
August 26, 2024 - How would I install the latest version of GNU? I am using image: cimg/base:stable for my Docker in each of my jobs. When I try the following, command, it only install C and CXX compiler versions 9.4.0, but I need minimu…
🌐
GitHub
gist.github.com › skyzyx › 3438280b18e4f7c490db8a2a2ca0b9da
Using GNU command line tools in macOS instead of FreeBSD tools · GitHub
I think most of us realize that macOS isn't a Linux OS, but what that also means is that instead of shipping with the GNU flavor of command line tools, it ships with the FreeBSD flavor. As such, writing shell scripts which can work across both platforms can sometimes be challenging. Homebrew can be used to install the GNU versions of tools onto your Mac, but they are all prefixed with "g" by default.
🌐
Digilent
files.digilent.com › manuals › DT7816_WebHelp › Install_GNU_Tools.htm
Install GNU Tools
# sudo apt-get install build-essential gcc make linux-headers-$(uname -r)
🌐
SourceForge
sourceforge.net › projects › gnuwin32
GnuWin download | SourceForge.net
Download GnuWin for free. Provides native Win32 open source ports and utilities. GnuWin provides Win32-versions of GNU tools, or tools with a similar open source licence. The ports are native ports, relying only on libraries provided with any modern 32-bits MS-Windows operating system, such ...
Rating: 4.6 ​ - ​ 78 votes
Top answer
1 of 4
11

Homebrew now has the GCC package so you can install it with this command:

brew install gcc
2 of 4
7

The way I do it is:

  1. Download the source for GCC and numerous supporting packages. The instructions are in the gcc-4.x.y/INSTALL/index.html file in the GCC source code, or online at http://gcc.gnu.org/install/.
  • GNU Multiple Precision Library (GMP) version 4.3.2 (or later) from http://gmplib.org/.
  • MPFR Library version 2.4.2 (or later) from http://www.mpfr.org/.
  • MPC Library version 0.8.1 (or later) from http://www.multiprecision.org/.
  • ISL Library version 0.11.1 from ftp://gcc.gnu.org/pub/gcc/infrastructure/.
  • CLooG 0.18.0 from ftp://gcc.gnu.org/pub/gcc/infrastructure/.
  1. Use a script to extract the source for GCC and the support libraries into a directory, create the object directory, and run the build.

This is the script I used for GCC 4.8.2:

GCC_VER=gcc-4.8.2
tar -xf ${GCC_VER}.tar.bz2 || exit 1

(
cd ${GCC_VER} || exit

cat <<EOF |
    cloog 0.18.0 tar.gz
    gmp 5.1.3 tar.xz
    isl 0.11.1 tar.bz2
    mpc 1.0.1 tar.gz
    mpfr 3.1.2 tar.xz
EOF

while read file vrsn extn
do
    (
    set -x
    tar -xf "../$file-$vrsn.$extn" &&
    ln -s "$file-$vrsn" "$file"
    )
done
)

mkdir ${GCC_VER}-obj
cd ${GCC_VER}-obj
../${GCC_VER}/configure --prefix=$HOME/gcc/gcc-4.8.2
make -j8 bootstrap

When that finishes, run the install too. Then add $HOME/gcc/gcc-4.8.2/bin (the name you specify in --prefix plus /bin) to your PATH ahead of /usr/bin.

With a decent MacBook Pro with a 5400 rpm spinning disk, it takes an hour or two to compile everything (using the -j8 option to make), and requires multiple gigabytes of disk space while compiling. SSD is nice when doing this (definitely faster)!


GCC 4.9.0 was released on 2014-04-22. I've installed it using basically the same process, but with CLooG 0.18.1 and ISL 0.12.2 (required updates) and GMP 5.1.3 (and 6.0.0a), MPC 1.0.2 (or 1.0.1) and MPFR 3.1.2 on Mac OS X 10.9.2 Mavericks and an Ubuntu 12.04 (Precise Pangolin) derivative. Beware that the gmp-6.0.0a.tar.xz extracts into directory gmp-6.0.0 (not gmp-6.0.0a as you might expect).


Between 2014 and 2017-09-27, I've built GCC versions 4.9.0, 4.9.1, 5.1.0, 5.2.0, 5.3.0, 6.1.0, 6.2.0, 6.3.0, 7.1.0 with only minor variations in the build script shown below for GCC 7.2.0 on macOS v10.12 (Sierra). The versions of the auxiliary libraries changed reasonably often.


macOS Sierra and High Sierra

On 2017-08-14, I used a minor variant of the script above to build GCC 7.2.0 on macOS v10.12 (Sierra) (using Xcode 8 as the bootstrap compiler). One change is that CLooG doesn't seem to be needed any more (I stopped adding it with GCC 6.2.0). This is my current script:

#!/bin/bash

#export DYLD_LIBRARY_PATH=$(clnpath $(dirname $(dirname $(which g++)))/lib:$DYLD_LIBRARY_PATH)
unset DYLD_LIBRARY_PATH

TAR=/opt/gnu/bin/tar
VER_NUM=7.2.0
GCC_VER=gcc-${VER_NUM}
TGT_BASE=/opt/gcc
TGT_DIR=${TGT_BASE}/v${VER_NUM}
CC=/usr/bin/clang
CXX=/usr/bin/clang++

extract() {
    echo "Extract $1"
    $TAR -xf $1
}

if [ ! -d "$GCC_VER" ]
then extract ${GCC_VER}.tar.xz || exit 1
fi

(
cd ${GCC_VER} || exit

nbncl <<EOF |
    gmp     6.1.2   tar.lz
    isl     0.16.1  tar.bz2
    mpc     1.0.3   tar.gz
    mpfr    3.1.5   tar.xz
EOF

while read file vrsn extn
do
    tarfile="../$file-$vrsn.$extn"
    if [ ! -f "$tarfile" ]
    then echo "Cannot find $tarfile" >&2; exit 1;
    fi
    if [ ! -d "$file-$vrsn" ]
    then
        (
        set -x
        extract "$tarfile" &&
        ln -s "$file-$vrsn" "$file"
        ) || exit 1
    fi
done
)

if [ $? = 0 ]
then
    mkdir ${GCC_VER}-obj
    cd ${GCC_VER}-obj
    ../${GCC_VER}/configure --prefix="${TGT_DIR}" \
        CC="${CC}" \
        CXX="${CXX}"
    make -j8 bootstrap
fi

Make sure your version of tar supports all four different compressed file formats (.lz, .gz, .xz, .bz2), but since the standard Mac version of tar does that for me, it'll probably work for you too.

On 2017-09-27, I failed to build GCC 7.2.0 on macOS v10.13 (High Sierra) (using Xcode 9 for the bootstrap compiler) using the same script as worked on v10.12 (Sierra). The immediate error was a missing header <stack>; I'll need to track down whether my Xcode 9 installation is correct — or, more accurately, why it isn't correct since <stack> is a standard header in C++98 onwards. There's probably an easy fix; I just haven't spent the time chasing it yet. (Yes, I've run xcode-select --install multiple times; the fact that I had to run it multiple times because of network glitches may be part of the trouble.) (I got GCC 7.2.0 to compile successfully on 2017-12-02; I don't recall what gymnastics — if any — were required to get this to work.)

Time passes; version numbers increase. However, the basic recipe has worked for me with more recent versions of GCC. I have 7.3.0 (installed 2018-01-2), 8.1.0 (installed 2018-05-02), 8.2.0 (installed 2018-07-26), 8.3.0 (installed 2019-03-01) and now 9.1.0 (installed today, 2019-05-03). Each of these versions was built and installed on the current version of macOS at the time, using the current version of Xcode for the bootstrap phase (so using macOS v10.14.4 (Mojave) and Xcode 10.2.1 when building GCC 9.1.0).