NOTE

1.4 MSYS2

MSYS2 installation, environment configuration, common tools, and IDE integration.

Developer ToolsCreated Updated 2 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Installation

MSYS2 Installation

2. Configuration

2.1. Configure Windows Environment Variables

The original note once added usr\bin, mingw64\bin, and mingw32\bin to the Windows PATH at the same time. Different MSYS2 environments use different CRTs, toolchains, and prefixes, so the bin directories of multiple environments should not be mixed together globally.

If you are unsure which environment to choose, prefer UCRT64. Let the MSYS2 launcher configure the environment for the current shell. For example, a UCRT64 shell puts /ucrt64/bin:/usr/bin first.

If you really need to inherit the Windows PATH, set this according to your actual needs:

MSYS2_PATH_TYPE=inherit

2.2. Modify MSYS2 Configuration Files

Usually there is no need to manually hard-code MSYSTEM into multiple configuration files. Prefer selecting the environment through the corresponding MSYS2 launcher.

If you need to start UCRT64 from a script, use msys2_shell.cmd under the installation directory:

<MSYS2_ROOT>\msys2_shell.cmd -defterm -here -no-start -ucrt64

The winsymlinks, nsswitch.conf, mirror-source settings, and similar settings in the original note are all machine-specific configurations. Modify them individually only when there is an actual need, and do not put personal absolute paths into public configuration.

3. Common Software

3.1. Installation

First update the system:

pacman -Syu

Install tools as needed in the UCRT64 environment. For example:

pacman -S --needed \
  mingw-w64-ucrt-x86_64-toolchain \
  mingw-w64-ucrt-x86_64-gdb \
  mingw-w64-ucrt-x86_64-ffmpeg \
  mingw-w64-ucrt-x86_64-graphviz \
  git rsync vim zsh fish

Specific package names may change with the repositories. Before installation, you can use pacman -Ss <name> to search.

3.2. Configuration

3.2.1. SSH

ssh.md

3.2.2. Git

git.md

3.2.3. GCC

gcc.md

4. IDE Integration

4.1. VSCode

You can make the VS Code terminal start an MSYS2 UCRT64 shell. The exact settings.json syntax changes with VS Code/MSYS2 versions; the core is to invoke:

<MSYS2_ROOT>\msys2_shell.cmd -defterm -here -no-start -ucrt64

4.2. GoLand

The GoLand Terminal can likewise point its shell path to:

"<MSYS2_ROOT>\msys2_shell.cmd" -defterm -here -no-start -ucrt64

If you are only building a Go project, there is no need to force MSYS2 into the IDE. Configure it only when the project depends on Unix tools or a local C/C++ toolchain.

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub