Install and Setup MSYS2 on Windows

#shell, #cli, #msys2, #windows

In this article, I’ll guide you through the process of installing and configuring MSYS2 on your Windows system.

What is MSYS2? #

MSYS2 is a software distribution and building platform for Windows. It provides a Unix-like environment and a collection of tools, utilities, and libraries aimed at enabling efficient software development and system administration tasks. MSYS2 offers a convenient way to work with command-line interfaces, execute shell scripts, and compile software projects originally designed for Unix-like operating systems.

Installing MSYS2 #

To get started with MSYS2, follow these simple steps:

  1. Download: Head over to the MSYS2 website (https://www.msys2.org/) and download the installer.

  2. Installation: Run the downloaded installer and follow the on-screen instructions. By default, MSYS2 installs to C:\msys64 for 64-bit systems or C:\msys32 for 32-bit systems.

    Attention! Install MSYS2 only on short ASCII-only path on a NTFS volume with no accents, no spaces, no symlinks, no subst or network drives, no FAT.

  3. Initialization: Once the installation is complete, there should be a shell launched automatically. If not, launch one of the MSYS2 shells ucrt64.exe or mingw64.exe from your MSYS2 installation directory.

  4. Update: In the MSYS2 shell, execute the following command to update the package database and core system packages:

     pacman -Syu
    

    MSYS2 uses pacman as it’s package manager.

MSYS2 Shell Environments #

MSYS2 offers different shell environments tailored to specific use cases, such as MinGW-w64 Shell, MSYS2 Shell, and UCRT64 Shell. Each environment provides a distinct set of tools and configurations, catering to different development needs and compatibility requirements.

For detailed information about MSYS2 shell environments, refer to the official documentation here.

Adding MSYS2 Shell as Profile in Windows Terminal #

If you’re using Windows Terminal as your preferred command-line interface, integrating MSYS2 shell is straightforward:

  1. Open Windows Terminal. If you don’t have Windows Terminal installed, you can get it from Microsoft Store (https://apps.microsoft.com/detail/9n0dx20hk701?hl=en-zm&gl=ZM).

  2. Navigate to Settings by clicking on the down arrow (v) icon in the title bar.

  3. In the sidebar, click Open JSON file to edit profile settings in JSON format.

  4. Open PowerShell in new tab and type:

     New-Guid
    

    Don’t close the tab yet, you’ll need these numbers later.

  5. Back to profile settings, search for profiles.list and add a new profile entry for MSYS2 shell there. For example:

     "profiles": 
     {
       "list":
       [
         {
           "commandline": "[MSYS2-INSTALLATION-DIRECTORY]/msys2_shell.cmd -defterm -here -no-start -[TERMINAL] -shell [SHELL]",
           "guid": "[{UNIQUE-GUID}]",
           "icon": "[MSYS2-INSTALLATION-DIRECTORY]/clang64.ico",
           "name": "MSYS2: Clang 64",
           "startingDirectory": "%USERPROFILE%",
           "tabTitle": "MSYS2: Clang 64"
         }
       ]
     }
    
    • Copy your previously generated guid in PowerShell and replace [{UNIQUE-GUID}] with it.
    • Replace [MSYS2-INSTALLATION-DIRECTORY] with your MSYS2 installation directory. Example: C:/msys64.
    • Replace [TERMINAL] with your terminal environment of choice such as msys2, mingw32, mingw64, ucrt64, clang32, clang64, clangarm64.
    • Replace [SHELL] with your favorite shell such as bash, zsh, fish.

    Here’s my final profile entry:

     {
       "commandline": "D:/Programs/msys2/msys2_shell.cmd -defterm -here -no-start -clang64 -shell zsh",
       "guid": "{2d6986ca-4616-4a8f-b3b1-121043a4a7db}",
       "icon": "D:/Programs/msys2/clang64.ico",
       "name": "MSYS2: Clang 64",
       "startingDirectory": "%USERPROFILE%",
       "tabTitle": "MSYS2: Clang 64"
     }
    
  6. Save the settings.json file and restart Windows Terminal (optional). You should now see MSYS2 Shell as an available option in the dropdown menu.

Further Reading #

I hope this guide has been helpful in getting you started with MSYS2 on Windows. If you encounter any issues or have additional questions, don’t hesitate to reach out in the comment section. I’d recommend you to read about setting up zsh on Windows.

References

  1. https://www.msys2.org/docs/terminals/
  2. https://stackoverflow.com/questions/71045716/adding-msys-to-windows-terminal