Building GHC on Windows

This page documents the instructions for setting up a Windows build using MSYS2, which is a fairly complete build of MinGW-w64 + the MSYS2 tools.

This guide should get you running in ~5 minutes, modulo download speeds.

msys2 setup

Download and run the msys2 installer (64-bit) (a 32-bit version is also available). Open a mingw64 shell.

IMPORTANT: the msys2 installer creates multiple shortcuts, "MSYS2 Shell", "MinGW-w64 Win32 Shell" and "MinGW-w64 Win64 Shell". You need the latter one (or the middle one for 32-bit). The MSYS2 shell is set up for building applications with Cygwin which provides an additional POSIX compatibility layer, while MinGW is set up for building native Windows applications which is what we need for GHC.

An easy way to check that you are running the right shell is to check the output of echo $PATH. The first item of the list should be /mingw64/bin. Also, echo $MSYSTEM should show either MINGW32 or MINGW64.

If you are using a preexisting msys2 installation, consider upgrading all installed packages to the latest versions. That takes a few steps, see MSYS2 installation instructions (section III).

Installing packages & tools

The msys2 package uses pacman (the venerable ArchLinux package manager) to manage packages. Let's install system dependencies required for building GHC:

pacman -Sy git tar binutils autoconf make libtool automake python2 p7zip patch gcc docbook-xsl

Note: dblatex isn't available as a MSYS2 package, so the user's guide won't be build in ps and pdf format (only html).

Host GHC setup

A host GHC binary is required for bootstrapping. Let's download and install a prebuilt GHC into /usr/local:

curl -L$(uname -m | sed -e s/686/386/)-unknown-mingw32.tar.xz | tar -xJ -C /tmp &&
mkdir -p /usr/local &&
mv /tmp/ghc-7.8.3/* /usr/local &&
rmdir /tmp/ghc-7.8.3

Cabal setup

Building ghc requires Alex and Happy. It is easiest to install them using cabal. We will also put them in /usr/local to make sure that they end up on $PATH.

curl -L | tar -xz -C /usr/local/bin &&
cabal update &&
cabal install -j --prefix=/usr/local alex happy

A Quick Build

You should now be able to build GHC:

cd ~ &&
git clone --recursive git:// &&
cd ghc &&
git clone git://

Consider setting up mk/ here (cp mk/ mk/ && vim mk/

Finally, to perform the actual build:

./boot &&
./configure &&

Running parallel make (e.g., make -j5) is faster, but appears to cause segfaults during the build sometimes. The reasons are not clear yet.

Msys2 is known to be glitchy in some situations. If you see errors related to fork(), try closing and reopening the shell; see also msys2 issue #74. Also there have been issues with the build process segfaulting. The reason is not known (we're looking into it). If that happens, simply rerunning make will continue the build process.

Alternatively, to run a pristine build and tests (takes a while):


NOTE: You may see an error like make 7628 child_info_fork::abort: ... make: fork: Resource temporarily unavailable when running make. To fix this, go to the root of your MSYS dir and run autorebase.bat; see and again Alternatively, run shutdown //r.

Other documentation

Other documentation for Windows includes:

Last modified 13 days ago Last modified on Jun 18, 2015 8:42:03 AM