- WSL2_4_Nix_Nerds - Introduction
- Pre-requisites
- Install WSL2
- Post-Install (the stuff you're here for)
- Linux Configuration
- ZSH
- VIM
- Tmux
- Controlling your instances
- References
A quickstart guide to getting Debian in WSL2 to an acceptable working state. If you have VMWare Workstation, Docker For Windows, or VirtualBox then the "VirtualMachinePlatform" feature MAY affect them by not allowing you to start up the VMs you have already built as this is run via Hyper-V. See FAQ
- Windows 10 (WSL 2 is only available in Windows 10, Version 1903, Build 18362, WSL 1 for earlier versions)
- Chocolately - Windows package manager which runs in Powershell (as Administrator). Its not necessary but will make finding and installing packages easier.
- Windows Terminal : https://docs.microsoft.com/en-us/windows/terminal/get-started
- Possibly a better powerline/Unicode/Colour support (I have not tested this yet): WSLTTY https://github.com/mintty/wsltty
- TrueType Fonts (TTF):
- Recommended MesloLGS Font from the PowerLevel10K is my new best friend.
- Just as good, Cascadia Code NerdFont (Makes text look awesome) -
choco install cascadia-code-nerd-font
- Microsoft's Cascadia Code Powerline (https://github.com/microsoft/cascadia-code/releases)
Really just follow the steps (https://docs.microsoft.com/en-us/windows/wsl/install-win10), but here's the quick steps I used: In PowerShell as Administrator
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart-Computer
- Install updated Linux Kernel : https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
- Set default WSL to version 2 :
wsl --set-default-version 2
- Install your preferred distro from the MS Store
- Run your installation and go through the install and initialization steps, username and password
- (Optional) VSCode On Windows (PowerShell as Administrator) -
choco install vscode
- WT Settings - Can be reached via Windows Terminal Settings,
Ctrl+,
or click on the down chevron next to the+
symbol in the tabline. If you haven't configured an editor for.json
files, it will ask you for one. I'm using VSCode. - See the Windows Terminal page for detailed customization options. This is where behaviour and look and feel (background images, transparency etc) are defined.
- Useful trick: If you have Windows Terminal running and while you have the configuration file open, when you save settings, Terminal will reload them right away and you can see what effect you've had on it right away.
Two ways to alter what your default profile will be. Right now it will launch PowerShell for you. To set it to Debian, from within PowerShell wsl -s Debian
. You can also set the "defaultProfile"
attribute to the GUID value of the Unix install from within the Settings json configuration file. Altering the order of the profile list will alter the order of your shell choices when you right click the WT icon.
- Launch your Debian instance via right-click on the Windows Terminal icon and choosing your Debian instance
- Choose your font, font size, and set your default start directory will be the
c:\users\<username>\
directory. If you perfer good old fashioned/home/<username>
then set it as per below. There are different ways fonts could be installed, either viachoco
or manually downloaded from Nerd Fonts. Make sure you have the correct font name by using the "Font" tool in the Start menu. You can put these in the"default"
section of the"profiles"
, or per profile. These examples are per profile and in the"name":"Debian"
profile for myself. Order of attributes doesn't seem to matter.
"startingDirectory": "//wsl$//Debian//home//gclair",
//"fontFace": "MesloLGS NF",
"fontFace": "CaskaydiaCove Nerd Font Mono",
"fontSize": 10,
- Copy on Selection:
"copyOnSelect": true
defaults tofalse
. Selection is copied to clipboard on selection. Right click will then always paste. - Paste Warnings (can be annoying):
"largePasteWarning"
or"multiLinePasteWarning"
set totrue
orfalse
per users choice. Defaults totrue
- DNS is usually broken - Networking info is obtained via WSL Ethernet interface and gets its own private host only subnet. Edit
/etc/wsl.conf
with the following to "permanently" fix it:
[network]
generateResolvConf = false
- Restart your Debian instance (Powershell): wsl -t Debian, launch WT Debian instance
- Fix resolv.conf (should no longer be updating):
sudo rm /etc/resolv.conf && sudo echo nameserver 8.8.4.4 >/etc/resolv.conf
- Yes its Google's NS, but i have flaky issues with Cloudflare it seems. - Debian doesn't install
man
by default or other useful packages:sudo apt update && sudo apt install keychain dnsutils vim man curl wget zsh git build-essential
- Homebrew on Linux - I find distribution repos don't necessarily have all the up to date/best versions of software. Brew won't install until you fix your networking and get curl or wget installed. Add brew and its packages to your $PATH :
/home/linuxbrew/.linuxbrew/bin
- FUN FACT You can launch your Windows Executables from here. Try it! If you have VSCode in Windows just run
code
. It will launch the Windows version of code that recognizes WSL! See the YouTube link in the references. For fun, hack yourself!calc.exe
.. Yes its a joke.
The accepted way to use SSH-agent and keep your sessions configured via tmux seems to be keychain
.
Added to my .zshrc
:
HOSTNAME=`hostname`
/usr/bin/keychain --nogui $HOME/.ssh/<MY_SSH_PRIVKEY>
source $HOME/.keychain/$HOSTNAME-sh
HOSTNAME is not set in WSL2, so if you don't change it often, hardcoding it will be fine.
- Switch to zsh:
chsh -s /bin/zsh <yourusername>
, restart WT session.
I like the usage of plugins with ZSH using Oh My Zsh! and Powerlevel10k which really exercise those NerdFonts well. They recommend using the Meslo Nerd Font.
I am a user of SpaceVim. It looks pretty and works relatively well for me. I didn't have to do many changes here. If you're an experienced dev, you have all your customizations in your github ready to go. I however, no not ¯\_(ツ)_/¯
This needs a section all its own, but if you got this far you know what you're doing.
I think the important part of tmux configuration is setting the terminal in your ~/.tmux.conf.local
OR ~/.tmux.conf
:
set -g default-terminal "xterm-256color"
or to "screen-256color"
. The xterm-256color seems to work for me.
When I installed powerlevel10k
and configured it with p10k configure
, the tmux.conf is configurues is very clever and includes cut and paste to the OS clipboard.
if -b 'command -v clip.exe > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | clip.exe"'
if -b '[ -c /dev/clipboard ]' 'bind y run -b "tmux save-buffer - > /dev/clipboard"'
- Instances are managed via powershell (admin) with
wsl
. wsl --list --verbose
ORwsl -l -v
: list your installed instanceswsl -s Debian
: Set your default distribution to start to the named "Debian" distro.wsl -t Debian
: Terminate the instance. Sometimes this is the 'reset' button you need- I've never had to start the WSL2 instance as this is done automatically when you start Windows Terminal *nix instance.
- https://docs.microsoft.com/en-us/windows/wsl/
- https://docs.microsoft.com/en-us/windows/terminal/tutorials/powerline-setup
- https://www.aaron-powell.com/posts/2020-04-24-a-walk-through-of-my-terminal-setup/
- https://www.aaron-powell.com/posts/2020-03-25-how-i-setup-a-windows-dev-environment/
- https://youtu.be/j0PPcUUtHlw <- Explanation of WSL1 vs WSL2, tips and tricks and making things pretty and functional.