Written 2020-11-05
In this guide, my intent is to install a bash & zsh terminals onto a Windows 10 machine such that they:
- Have easy access to the Windows filesystem
- Run almost as fast as a native implementation
- Have a good baseline vim config without additional work
- Support copy/cut/paste with
Ctrl+C
,Ctrl+X
,Ctrl+V
like normal - Depend on only software that I have used and know works well
- Support colour themes to liven up your terminal!
This process is based on Nuno Caneco's guide which references Sebastian Gingter's guide, plus a hack to make it all work under Windows Subsystem for Linux 2 (WSL2) that you can find here.
I'm also leaning on Microsoft's WSL install guide and it might be a valuable resource if you run into trouble.
-
Open the Windows Store app.
-
Install the Ubuntu app by Canonical Group Limited.
-
Open a Powershell terminal as Administrator.
-
Run the following command to install WSL:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
-
Run the following command to install VM features for WSL2:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Reboot your computer. Yes, really.
-
After rebooting, run the Ubuntu app to confirm that a bash terminal starts up. You may need to set a username & password for your Ubuntu user at this point.
-
Run the following command at your Ubuntu bash terminal to create a symlink from your Ubuntu home (~) to your Windows user folder:
ln -s ~/win10 /mnt/c/Users/<your Windows username>
-
Congratulations! You have bash on Windows. But we're only getting started...
-
Download the full version of Cmder (https://cmder.net/)
-
Cmder is a portable app, so unzip it to any folder you want it to live in. I typically use
C:\Users\<username>\.portable
for my portable apps (soC:\Users\<username>\.portable\Cmder
in this case). You'll probably also want to send a shortcut toCmder.exe
to your desktop or link to it in some other way for convenience. I always set this shortcut to "Run as Administrator" but I'm not sure this is required. -
Run Cmder and watch its default terminal work. We're going to ignore that from here on out. Click the green plus to open a new terminal and select
{WSL::bash}
. If you get an error like this, you need to follow step 4 (otherwise you can skip to step 5):wslbridge error: failed to start backend process note: backend error output: -v: -c: line 0: unexpected EOF while looking for matching `'' -v: -c: line 1: syntax error: unexpected end of file ConEmuC: Root process was alive less than 10 sec, ExitCode=0. Press Enter or Esc to close console...
-
If Cmder errors out on WSL Bash, you need to replace the wslbridge that failed in the error with wslbridge2. The Github issue comment where the following solution is invented is here if you want context. The solution goes like so:
-
Recall the folder you unzipped Cmder to. Use explorer to navigate to
<your Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\
and renamecygwin1.dll
tocygwin1-backup.dll
. We're going to replace this file but keeping a backup never hurts. -
Download the latest release of wslbridge2 from https://github.com/Biswa96/wslbridge2/releases. I downloaded the
x86_x64
version of releasev0.7
but newer versions will probably work fine (famous last words?). -
Extract
wslbridge2_cygwin_x86_64.zip
to<your Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\
. Note that this creates a newcygwin1.dll
that we're going to overwrite. -
Delete the newly extracted
<your Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\cygwin1.dll
. We don't need to back this up, but you can rename it instead if you're paranoid. -
Go to https://cygwin.com/snapshots/ and download the latest
cygwin1-XXXXXXXX.dll.xz
. I downloadedcygwin1-20200909.dll.xz
but newer versions will probably work fine (famous last words?). -
Use 7-Zip to open your
cygwin1-XXXXXXXX.dll.xz
and extract it to<Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\
. -
Rename
cygwin1-XXXXXXXX.dll
tocygwin1.dll
.
-
-
In Cmder, press
Win+Alt+T
to open the Tasks Settings. -
Select the
{WSL::bash}
task and edit its command (the bottom text field) to the following:set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe %ConEmuBaseDirShort%\wsl\wslbridge2.exe - -cur_console:t:bash cur_console:pm:/mnt -eConEmuBuild -eConEmuPID -eConEmuServerPID -l -W ~/win10
-
Exit the settings and open a new
{WSL::bash}
terminal again. It should open to a terminal without errors this time. -
Congratulations! You have a pretty solid bash with decent colouring and vim defaults for Windows. But we can go deeper...
-
Open your new
{WSL::bash}
terminal in Cmder. -
Run the following command at your bash terminal to install
zsh
:sudo apt-get install zsh
-
Edit your
~/.bashrc
file (I use vim but using whatever *nix text editor you like) to include the following, right at the top of the file and save it:if test -t 1; then exec zsh fi
-
Open a new
{WSL::bash}
terminal. You will be presented with the zsh setup wizard. I leave the details of this setup to you to figure out. It's your terminal! -
At this point, you should be sitting on a zsh terminal. To prove it, you can run
ps
and ifzsh
is one of the active processes then your golden!-
You may want to rename your
{WSL::bash}
terminal to{WSL::zsh}
in Cmder. -
You can also replace
cur_console:t:bash
in the command string withcur_console:t:zsh
so the terminal tab is named correctly in Cmder.
-
-
Run the following command at your zsh terminal to install
oh-my-zsh
:sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
-
If you want to install a terminal theme, you can choose from the available options then edit the value of the
ZSH_THEME
variable in your~/.zshrc
to the name of your chosen theme. There are even more available options but you'll need to download these separately to use them. I like powerlevel10k myself, but this is an exercise for the reader. -
Congratulations! You might just have the nicest terminal that's ever been available on a Windows machine!
The instructions above cover the necessary steps to get zsh working and looking pretty, but there are some more things you might want to do to get the most out of this setup.
-
To make your WSL2 Ubuntu files more easily accessible from Windows, consider mapping
\\wsl$\Ubuntu\
as a network drive. This will allow you to quickly and easily navigate to your Ubuntu root folder (/
). Just type\\wsl$
into explorer, right-click on the Ubuntu folder, selectMap network drive
and pick your favourite letter for the drive. -
Cmder's general settings include a colour theme of its own that interferes with the colours of oh-my-zsh themes. You might need to fuss with these to get the best look. I haven't figured out how to bypass this yet.
-
Definitely set up your
{WSL::zsh}
terminal as the default for new terminal windows in Cmder. -
Consider installing a nice monospace font for your new terminal. Here are a few recommendations:
-
Consider upgrading your WSL2 Ubuntu from 20.04 to 20.10. It really does open up some exciting new possiblities for what you can do with it (like some of the recommended tools below).
-
Consider adding some other spicy *nix tools to your Windows terminal:
- bat is a more colourful and usable version of
cat
- exa is a more colourful and usable version of
ls
- fd is a more colourful and usable version of
find
- httpie is a more colourful and usable version of
curl
- fzf is a powerful fuzzy-search tool. In particular, it supports keybinds such as
Ctrl+R
to fuzzy search your command history orAlt+C
to fuzzy-find files recursively from your current folder.
- bat is a more colourful and usable version of
-
I like to add the following lines to the end of my
~/.zshrc
to automatically start up my SSH agent and install my SSH key so I can use Github without interruption:echo "Starting SSH agent..." eval $(ssh-agent -s) ssh-add ~/.ssh/<private key file>