An installation/configuration guide to help setting up MSYS2 on microsoft windows and use it in Visual Studio Code
MSYS2 is a terminal software for microsoft windows operating system providing us different terminal shells (e.g., bash, zsh and etc.) alongside with important tools (e.g., gcc, git and etc.). It is bundeled with its own package manager and software repository letting us have access to the latest binary versions of many development necessity tools. Although the benefits of this software are very good, the setting-up procedure, specially to configure it on Visual Studio Code might be tricky. Also there are some points in correct installation and usage which if not handled properly it might cause the program to crash.
Before installing MSYS2 it is good to perform some actions to avoid further problems.
- Run registry editor (ctrl r and type in regedit).
- Go to the address
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor
. - Delete
Autorun
key if it is present there.
In this way we make sure that windows command prompt will work properly and will not cause further problems.
To install MSYS2 on microsoft windows operating system please follow the steps below:
- Go to the MSYS2 releases page and download the latest .exe version of the installer (the
msys2-x86_64-release_date.exe
file). - Run the downloaded installer file (You might want to run it as an adminstrator.)
- Click on Next.
- Choose your favorite path of installation and click on Next. (Note that the path must be without any spaces)
- Choose the start menu shortcuts folder name and click on Next.
- Let the installer to extract file.
- Check the
Run MSYS2 64bit now.
and click on Finish.
A MSYS2 instance will pop up. Please follow the below instructions to complete the MSYS2 installation procedure:
- Run the command
pacman -Syu
and enter Y if a confirm is asked. This will update the package repository data for MSYS2. - Run the command
pacman -Su
and enter Y if a confirm is asked. This will update all installed packages on MSYS2. - (Optional) You may want to have GNU Compiler Collection (GCC) or GIT. To have them installed please run the command
pacman -S --needed base-devel mingw-w64-x86_64-toolchain git
- (Optional) Search for
Edit the system environment variables
in the start menu and open it, then click onEnvironment Variables
. From theUser variables for your_username
, select Path and click onEdit
thenAdd
and enterC:\msys64\mingw64\bin
. (You may replaceC:\msys64
with your main installation location of MSYS2). After this you will have access to MSYS2 installed packages from other terminals.
You may use Visual Studio Code (VSCODE) as your favorite IDE and want to use MSYS2 as the default terminal. In order to add MSYS2 as an available terminal and set it as default terminal please follow the steps below:
- In Visual Studio Code go to
File -> Preferences -> Settings
(or usectrl ,
keyboard shortcut) and click on the Open Settings (JSON) (Or look forterminal.integrated.profiles.windows
setting and click onEdit in settings.json
) - Add the following lines inside the settings.json file.
"terminal.integrated.profiles.windows": { "BASH": { "path": "C:\\msys64\\usr\\bin\\bash.exe", "args": [ "--login", "-i"], "env": { "MSYSTEM": "MINGW64", "CHERE_INVOKING": "1", "MSYS2_PATH_TYPE": "inherit"} } }, "terminal.integrated.defaultProfile.windows": "BASH", "git.path": "C:\\msys64\\usr\\bin\\git.exe"
- Restart the Visual Studio Code.
- Go to
Terminal -> New Terminal
(or usectrl shift `
keyboard shortcut) - The loaded terminal will be an MSYS2 terminal (MINGW64)
If you use oh-my-zsh and you see a \
at the beginning of your terminal lines, there is a fix for it which is as following:
- Just add the following inside the settings.json file.
"terminal.integrated.windowsEnableConpty": false
- Restart the Visual Studio Code.