Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save Zhendryk/22031313f6b13e0db582db351f5c7e51 to your computer and use it in GitHub Desktop.
Save Zhendryk/22031313f6b13e0db582db351f5c7e51 to your computer and use it in GitHub Desktop.
How to set up the ultimate Windows development environment

Setting up the Ultimate Windows Development Environment

WSL 2, Oh-My-Zsh, Windows Terminal, Git, VS Code, and VcXsrv!

The Operating System: WSL 2

Windows Subsystem for Linux Installation Guide (Windows 10)

0. Prerequisites

Ensure you are running Windows 10, Version 2004, Build 19041 or higher

You can check your windows version by hitting Win+R, typing winver and selecting OK

1. Install Windows Subsystem for Linux (WSL)

Before installing any Linux distributions from the Windows store, you must enable the WSL optional feature.

Open PowerShell with administrator priveleges and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

2. Enable the Virtual Machine Platform optional component

Open PowerShell with administrator priveleges and run:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your machine to complete the WSL install and update to WSL 2.

3. Set WSL 2 as your default version

Open PowerShell and run:

wsl --set-default-version 2

4. Install your Linux distribution of choice from the Microsoft Store

Grab your favorite Linux distribution from the Microsoft Store, I am using Ubuntu 20.04 LTS

Once you have installed it, you will need to launch it and set up the distribution with a user account and password.

5. Set your distribution's version to WSL 2

List your distributions with the following command:

wsl --list --verbose

Set your distribution to the version of WSL you want (1 or 2) by running:

wsl --set-version <distribution name> <version number>

The Style: Oh-My-Zsh (in WSL)

NOTE: This information was gathered from this article and this article, check them out!

0. Prerequisites

Oh-My-Zsh will require the installation of Powerline fonts in Windows to look correct with certain themes. To install them easily, run the following in Powershell:

git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
.\install.ps1

If PowerShell gives errors about not being able to run scripts, follow these steps (in PowerShell):

  1. Get your current user's execution policy with Get-ExecutionPolicy CurrentUser, and remember that for Step 4
  2. To unlock your PowerShell to run scripts (temporarily), run Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
  3. Run .\install.ps1 in the fonts directory to install all of the Powerline fonts
  4. After that is finished, run Set-ExecutionPolicy -ExecutionPolicy <original policy from step 1> -Scope CurrentUser

1. Installing Zsh and Oh-My-Zsh

To install zsh, open your Linux distribution terminal and run:

sudo apt-get install zsh

To install Oh-My-Zsh, run the following in your Linux distribution terminal:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

2. Configuring your shell

Open your ~/.bashrc file using nano ~/.bashrc, so we can tell it to execute zsh by default instead of bash:

if test -t 1; then
    exec zsh
fi

Restart your Linux distribution terminal

Now, we configure your zsh shell settings (which should now launch automatically by default). Open your ~/.zshrc file with nano ~/.zshrc:

# Find and change this
ZSH_THEME="robbyrussell"

# To this
ZSH_THEME="agnoster"

Save the file and restart your terminal again

Now, we need to install a new color theme for the terminal, because the default is... eye-meltingly terrible.

  1. You can pick a theme from this github repository
  2. Download the file of your choosing into the user home directory:
# using dircolors.ansi-dark
curl https://raw.githubusercontent.com/seebi/dircolors-solarized/master/dircolors.ansi-dark --output ~/.dircolors
  1. Edit your ~/.zshrc and place this in it:
## set colors for LS_COLORS
eval `dircolors ~/.dircolors`

The Shell: Windows Terminal

Now, what if there was a nice looking & performant terminal, where you could launch your WSL linux shell, PowerShell, Azure Cloud Shell, or even (god forbid) Command Prompt, all in one place? Good news, there is: Windows Terminal

  1. Install Windows Terminal
  2. Launch Windows Terminal, and click the dropdown arrow next to the + in the tab bar, and select Settings
  3. This should open a json file. If you like, you can set the default shell to your Linux distribution by copying the guid field from the profile which contains your Linux distribution information into the defaultProfile field towards the top of the file
  4. Create a new field in your Linux distribution profile to set the (presumably Powerline) font of your Linux shell, like so: "fontFace": "DejaVu Sans Mono for Powerline",
  5. Create another new field in your Linux distribution profile to set the color scheme of the shell, I am using the Solarized Dark theme: "colorScheme": "Solarized Dark",
  6. Save and exit the settings.json file

Windows terminal should now launch your Linux distribution shell by default when it launches now (if you configured it that way), with the proper color scheme and font of your choosing! Nice!

The Version Control: Git

Assuming git has already been installed by default on your Linux distribution (if it hasn't, run: sudo apt-get install git), you should run the following commands to start configuration:

git config --global user.name "<Your name here>"
git config --global user.email <Your email here>
git config --global core.editor "<Path to your favorite text editor executable here (Windows path following `/mnt/c/Users/<username/... convention>`)>"

Now, most developers either already do or should have some sort of security in place for authenticating their git access, whether that be with two-factor authentication, SSH, or some combination of those and possibly others (GPG keys, etc.). One gotcha with WSL is that you are essentially loading an entire secondary operating system within your current one, and it acts as such. This means by default, it will expect to have its own set of SSH keys and the like, but we don't want to hassle with that...

Share your existing SSH keys from Windows with WSL

NOTE: This information was found from this great article, check it out!

Assuming you don't use GitHub desktop, and you set up your SSH keys following this guide from GitHub, you can take advantage of the fact that Git on Windows has a handy-dandy executable called the Git Credential Manager. Basically, once you set up some authentication credentials with GitHub to your computer, and you successfully authenticate, the Git Credential Manager will store those credentials so that you don't have to retrieve them every time you execute a git command. So, knowing this, we can follow these steps to share our pre-existing Windows authentication with WSL:

  1. Copy your existing SSH keys over to the WSL filesystem home directory:
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
  1. You'll probably run into a permissions error if you try to execute any git commands with those files, so we want to add Read/Write access for the owner, and no access for anybody else for that SSH file:
chmod 600 ~/.ssh/id_rsa
  1. Now, run the following git config command to finalize things:
git config --global credential.helper "/mnt/c/Program Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
  1. If you have a passphrase set up with your SSH keys, you'll probably want to configure it so it doesn't ask for it every time you run a git command. This is because the SSH agent isn't running on WSL. First, install keychain with sudo apt install keychain, and then add the following to your ~/.zshrc file:
eval ``keychain --eval --agents ssh id_rsa

Now, you'll only have to enter your passphrase once each time you reboot your machine, or terminate WSL.

The Editor: VS Code

Every developer needs a text editor (or an IDE, if you're into that), my personal preference is Visual Studio Code. Lets get it set up:

  1. Download/install VS Code on Windows, not WSL! from here
  2. Once you get that set up, you'll need to launch it & install a few extensions. Either use the Ctrl+Shift+X keyboard shortcut, or go to View->Extensions, which should pop up a menu on the side.
  3. Search for and install the Remote - WSL extension to support development in WSL.
  4. Optionally (but encouraged), also install a new color theme (I recommend Night Owl), and some other extensions, such as: Better Comments, Bracket Pair Colorizer 2, Material Icon Theme, Markdown All in One, Path Intellisense, Prettier - Code formatter, and various ones supporting your favorite programming languages!
  5. Now, to set your default embedded terminal to WSL, simply press Ctrl+Shift+P and search for/select Terminal: Select Default Shell and select WSL.

NOTE: To open a folder from the WSL file system in your Windows VS Code executable, you may need to either navigate to that folder in your terminal and run explorer.exe ., right click on the folder and select "Open with Code", or run the following command from within the desired folder in your terminal: code .

The Bonus: VcXsrv

This last section is a bit niche, and you may not care about it, so if this doesn't apply to you, feel free to skip it.

If you plan on developing any sort of GUI application from within WSL, you will need to install and configure a Windows X-server for WSL to output to, as WSL itself does not support display applications. VcXsrv is an Open-Source and regularly updated software that allows this interaction, and you can download it here

Install it with all of the default options. If it asks you about Firewall permissions, allow it through your local network firewall, but not for public networks, and then follow these steps to get it set up:

  1. The executable is (not helpfully) called XLaunch, so launch that, and select the following options, in order:
    • Page 1
      1. Select Multiple Windows
      2. Set Display Number to 0
    • Page 2
      1. Select Start no client
    • Page 3
      1. Make sure Clipboard and Primary Selection remain checked, or check them if they aren't by default
      2. Uncheck Native opengl
      3. Check Disable access control
      4. Add -ac to the Additional parameters for VcXsrv text field
    • Final page
      1. Hit Finish
      2. Optionally, if you don't want to have to do this every time, you can hit Save Configuration to a file, which acts as a shortcut you can double click to launch VcXsrv with all of the settings you chose
  2. In your WSL shell, add the following to your ~/.zshrc file:
# To run GUI applications from WSL, run them on VcXsrv (XLaunch)
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

The above environment variable is neccessary for your WSL to make the connection to your (currently running) VcXsrv server on the Windows side of the world.

Lets test it out! Run the following command to install a test application:

sudo apt-get install x11-apps

Then, while ensuring that VcXsrv is currently running on Windows with the aforementioned settings, run this from your Linux terminal:

xeyes

Hopefully, if all went according to plan, a GUI window should pop up with eyes that follow your cursor! If something went wrong along the way, all of the original information that was compiled for this document is present in the relevant links under each section.

Congratulations! You've got a kickass development environment in Windows (this is the first time that sentence has ever been uttered)

@anwalkers
Copy link

@Zhendryk If you install WSL2 on Windows 11 you don't need the X Windows server any longer...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment