Skip to content

Instantly share code, notes, and snippets.

@ronnaf
Last active May 26, 2022 15:08
Show Gist options
  • Save ronnaf/0bef62a2bf093862286967d6d7b0ed44 to your computer and use it in GitHub Desktop.
Save ronnaf/0bef62a2bf093862286967d6d7b0ed44 to your computer and use it in GitHub Desktop.
Setting up MSYS2 with ZSH on Windows 11

Setting up MSYS2 with ZSH on Windows 11

If you want to code in Windows 11 but prefer the familiarity of a Unix environment.

Install MSYS2

MSYS2 provides a minimal shell required to run autotools and other build systems which get the source for software from the Internet from different repositories, configure them and build them. The shell and core tools exist mainly to allow porting Unix programs to run natively on Windows (i.e. without requiring a POSIX emulation layer).

To install MSYS2, follow this guide in the official MSYS2 docs.

Why not WSL2? Cygwin?

Run MSYS2 inside Windows Terminal (or Preview) - optional

If you don't wanna use Mintty (the default terminal application in MSYS2), you may run MSYS2 in Windows Terminal instead.

  1. Open Windows Terminal settings. If you are using Windows Terminal Preview, this will open GUI. You need to click "Open JSON file" to open settings.json.
  2. MSYS2 has provided Windows Terminal profiles here. Copy the profiles, and paste them in settings.json. If you have other profiles, be careful not to overwrite them. At the time of writing, here are the profiles:
"profiles": {
  "list":
  [
    // ...
    {
      "guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
      "name": "MINGW64 / MSYS2",
      "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64",
      "startingDirectory": "C:/msys64/home/%USERNAME%",
      "icon": "C:/msys64/mingw64.ico",
      "fontFace": "Lucida Console",
      "fontSize": 9
    },
    {
      "guid": "{2d51fdc4-a03b-4efe-81bc-722b7f6f3820}",
      "name": "MINGW32 / MSYS2",
      "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw32",
      "startingDirectory": "C:/msys64/home/%USERNAME%",
      "icon": "C:/msys64/mingw32.ico",
      "fontFace": "Lucida Console",
      "fontSize": 9
    },
    {
      "guid": "{71160544-14d8-4194-af25-d05feeac7233}",
      "name": "MSYS / MSYS2",
      "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -msys",
      "startingDirectory": "C:/msys64/home/%USERNAME%",
      "icon": "C:/msys64/msys2.ico",
      "fontFace": "Lucida Console",
      "fontSize": 9
    },
    // ...
  ]
}
  1. If you want MSYS2 to be the default profile Windows Terminal starts up when opened, set MSYS / MSYS2's guid (currently {71160544-14d8-4194-af25-d05feeac7233}) as the defaultProfile.

Install oh-my-zsh

Install zsh shell and curl to download the oh-my-zsh install script:

pacman -S zsh curl

Install oh-my-zsh with:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

If you wanna customize your oh-my-zsh set up, head over to the Using Oh My Zsh section of their official docs.

Set zsh as your default MSYS2 shell

  1. Locate MSYS2 installation folder in windows. In my case, it's in C:\msys64.
  2. Open msys2_shell.cmd.
  3. Locate line set "LOGINSHELL=bash" and change it to set "LOGINSHELL=zsh"

Now every time MSYS2 is opened, it will load zsh as the default shell.

Expose packages installed in MSYS2 to Windows

  1. Open "Run" by pressing Windows + R, and type in systempropertiesadvanced.
  2. Click on the "Environment Variables" button.
  3. In the "System Variables" section, scroll down and double-click on the "Path" variable. 4a. If you’re on Windows 7/8, add the text C:\msys64\usr\bin;C:\msys64\usr\local\bin; to the beginning of the variable value. 4b. If you’re on Windows 10+, add the C:\msys64\usr\bin and C:\msys64\usr\local\bin folders to the list.

To test if this is working, open a Windows Command Prompt and paste the following:

grep --help

If it shows you the man page(s) of grep, you're good to go!

Why not WSL? Cygwin?

The MSYS2 team has provided a comparison between MSYS2 and other Projects. You can check that out to see if it aligns with you use case.

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment