In my new job as a consultant and developer in Machine Learning and AI at Savantic AB, although we internally have a "choose your favorite OS" policy, we're from time to time running into situations where we need to do development on or for Windows. Being a heavy user of the Bash terminal on user on Xubuntu Linux myself, this quickly had me frustrated with how to do things quickly and efficiently on the commandline. The default terminal on windows (aka cmd.exe) is not the nicest thing to have to deal with, and the much more powerful PowerShell is different enough from bash that it will cause some frustration and grief.
So, what I was looking for was a no-fuss, lightweight, robust and as simple as possible solution to running my normal Bash-based workflow, but inside the main Windows filesystem, interacting with the Windows world. Turns out there are some solutions (hint: look at the thumbnail picture to the right). Read on for more info on that.
Windows Subsystem for Linux too heavy
First, I must mention the impressive work by Microsoft on the Windows Subsystem for Linux (aka. WSL), which more or less lets you run a full-blown (at least GUI-less, and not even completely GUI-less) distribution of popular Linux distros like Ubuntu and Fedora. WSL is awesome, but also kind of heavy to install, easily taking something closer to an hour to install (or that was my impression). It also has some odd behaviours like opening files in Windows from WSL will give you troubles with line endings (as you might know Windows uses \n\r for line endings while Linux uses just \n). Finally, the default bash terminal for WSL did not even have zoomable text. All in all, this made it clear that this is not the light-weight simple solution I was looking for. WSL is awesome, but too heavy that I will be comfortable to quickly install it on "any Windows machine" I need to spend time working on.
Enter Git-Bash and MSYS2
Thus, I continued my search. I found Git-Bash, which is part of the Git package for Windows. It provides a simple bash environment with git pre-installed and configured, and works extremely well for simple tasks.
The main drawback I found with Git-Bash was that it does not contain or allow an easy route to install my favorite terminal multiplexer / window manager: tmux. One nice blog post mentioned the system that Git-Bash builds upon, and that it sports a package manager which can install a lot more software: MSYS2. Long story short: I tried MSYS2, and now I'm (figuratively) in love. With a few (fixable) caveats I now can run pretty much my full command-line bash+tmux+vim+git(+etc etc) workflow from Xubuntu, IN WINDOWS, right inside the Windows filesystem ... and things just work!
So, for my own and others' documentation, I below provide documentation of the procedure I have so far followed to enable a comfortable very Linux-like bash environment in Windows.
How to set up a nice environment based on MSYS2
- Install MSYS2 by following the instructions here.
- Start MSYS2 from the start menu in Windows.
- Run upgrades of packages with the pacman packager:
- Hard restart terminal
- Install packages with
pacman -S <package>
- Some packages I installed:
- tig (The awesome text-mode interface to git)
- man-db (for manual pages)
- Some packages I installed:
- Install the python 3.7 Windows package from python.org
- Configure git to check out files with Windows style line endings, but check in with Linux style ditto:
git config --global core.autocrlf true
- Make python scripts properly print output continuously:
alias python='winpty python.exe'
- For Python development,
- Install the Chocolatey package manager, for installing many open source programs via the commandline, by following these instructions.
- If you run Windows in VirtualBox, make sure to enable bidirectional clipboard in VirtualBox, by right clicking on the virtual machine and choosing:
"Settings > General > Advanced" and setting "Shared clipboard" to "bidirectional".
If you follow the above instructions roughly, you might end up with an environment like this:
So far, I'm super pleased with this setup.
I noticed the following caveats:
- For pasting in terminals in Windows:You use Shift + Insert instead of the normal Ctrl + Shift + V from Linux.
- At least for Git-Bash, you need to name you ssh-keys
~/.ssh/id_rsa, not some custom name like ~/.ssh/.id_rsa_gitlab, or it won't be picked up (haven't tried with MSYS2 yet). There should be a way to change this, but I haven't had the time to check it up just yet.