Getting Started with MSYS2
I’ve used Cygwin for over a decade and only recently (a couple of years ago) learned about MSYS2. Cygwin, as one of my CS professors used to say, helps make Windows a real operating system. Saying something like that used to inevitably lead to one of those Windows vs Linux arguments. However, Microsoft seems to have finally agreed with the detractors and decided to bring BASH shell to Windows. This feature seems to only be available in Windows 10, so those still working with Windows 7 still have to fend for themselves.
One thing I didn’t like about Cygwin, however, was the installer. Mirrors would come and go and the package selection window was not intuitive – very “Windows-y”, in fact. That’s why I was pleasantly surprised by MSYS2. A package manager like pacman was what was missing in Cygwin, at least for me.
MSYS2 is not without bugs, either. For instance, when updating packages, it sometimes asks that you “not return to shell” and instead terminate program. You then might need to run the pacman update command again to make sure the update finishes.
I also have not been able to create a shortcut to it on the Desktop or Taskbar. When you search for it, it shows multiple versions (i.e., MSYS2, MSYS2 MinGW 64-bit, MSYS2 MINGW 32-bit). Other than that, it is a much better alternative in terms of user experience.
Why
A much more important question might be, “Why? Why use Windows at all?” Today, I do not use Windows as a primary dev environment. I used Windows exclusively up until I went to college. I was then introduced to Knoppix (with a “live CD”), and to Ubuntu shortly thereafter. My world changed drastically. I had an Ubuntu/Windows dual-boot setup on my Sony Vaio for a few years (the Windows was just in case I needed to use something like Adobe Photoshop or AutoCAD). When I started working as a .NET Developer, the first thing I did on my new machine was to install Cygwin.
Over the course of five years or so, I slowly made the transition to Mac. It has been one of the best decisions of my life. Much of the enterprise world still uses Windows, however. As a consultant, I interact with organizations that are still dependent on Windows. Most of them provide a Windows machine in order for us to connect to their network.
This is why I still depend on something like MSYS2.
Getting started
# Check mirrors (alter as needed). Check this after every update.
for i in $(ls /etc/pacman.d/mirrorlist.*); do echo $i; done
# Update system.
pacman -Syu
# Install dev tools (python, make, etc).
pacman -S base-devel --needed
# Utility tools.
pacman -S rsync unzip tar diffutils man git svn vim python3-pip
# AWS CLI.
pip3 install awscli
# Get .vimrc.
curl -LO https://raw.githubusercontent.com/henokmikre/dotfiles/master/.vimrc
# Install Vundle.
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# Install vim plugins (from .vimrc).
vim +PluginInstall +qall
# Create useful aliases.
echo "alias vi='vim'" >> ~/.bash_profile
echo "alias ll='ls -l'" >> ~/.bash_profile
source ~/.bash_profile
# Create SSH key.
# https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
ssh-keygen -t ed25519 -C "your_email@example.com"
The home directory is located at /c/msys64/home/$(whoami) (as opposed to /cygdrive/c/cygwin/home/$(whoami) in Cygwin).
Installing PHP
It is nice to have the PHP CLI for, say, running a script in a React application’s postbuild. Update all packages first. The update process often asks you to close the window, so make sure you don’t have another MSYS2 window open.
# Update all packages.
pacman -Syu
# Search for the PHP package.
pacman -Ss php
# Install it.
pacman -S php
# Verify.
php --version
If package signatures fail, it may be necessary to update the pacman keys.