Install MSYS2 on Windows

MinGW brings GNU compiler tools to Windows since the late 1990s. MSYS2 provides numerous developer tools including MinGW on Windows using pacman package manager.

Install MSYS2 by downloading msys2-x86_64-*.exe and run the installer, installing to %SYSTEMDRIVE%/msys64. MSYS2 needs to be on a non-FAT / non-ExFAT drive capable of symbolic links such as NTFS.

Start the MSYS2 console in the Windows Start menu. Update MSYS2 to get the latest packages in the MSYS2 terminal. Run this command multiple times until it says “nothing to do”.

pacman -Syuu

To use MSYS2 / MinGW64 programs from PowerShell without disrupting other compiler use, create ~/gcc.ps1 containing:

$Env:CC="gcc"
$Env:FC="gfortran"
$Env:CXX="g++"
$Env:path += ";$Env:SystemDrive/msys64/mingw64/bin/"

When it’s desired to use MSYS from a PowerShell prompt run ~/gcc.ps1.

From MSYS2 command prompt, search for packages like:

pacman -Ss gcc

MSYS2 packages of interest for scientific computing include: gcc, gdb, gcc-fortran, clang, boost, lapack, scalapack, HDF5, ninja, make, pkgconf, aspell.

You may need to reorder directories in the Windows Path variable. For example GNU Octave may need to be moved lower in the Path list or removed from Path.

If you find that MSYS2 is using more 500 MB, try clearing the package cache of old package versions

pacman -Sc

The MSYS2 latest package update feed shows recently updated packages. The MSYS2 Install reference is also useful. PowerShell per-session variable set is useful to set CC, FC, CXX to single intended compiler to build systems.

Comparison

The advantages of MSYS2 over complementary approaches include:

  • Cygwin:
    • MSYS2 works from the Windows Command Prompt or PowerShell
    • MSYS2 provides native Window binaries
    • Cygwin does not have a command-line package installer
  • Windows Subsystem for Linux: does not give Windows binaries
  • WinGet idea was taken from AppGet by Microsoft.
  • Chocolatey provides many general Windows programs of interest to end users. MSYS2 is available via Chocolatey:
    choco install msys2
  • Scoop is similar to Chocolatey, but more developer oriented. MSYS2 is available via Scoop:
    scoop install msys2