Skip to content

Instantly share code, notes, and snippets.

@seklyza
Last active December 4, 2020 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seklyza/39dd0190c8fa0cffd1e3f78959e848c4 to your computer and use it in GitHub Desktop.
Save seklyza/39dd0190c8fa0cffd1e3f78959e848c4 to your computer and use it in GitHub Desktop.
WSL Installation Guide

WSL 2 Installation

Step 1 - Checking whether your Windows version is compatible with WSL 2.

Run winver from the start menu

Run winver from the start menu.

Windows version

If your version is 2004/20H2 (or higher) - you're good πŸ‘! If not, you need to upgrade Windows 😒. In order to upgrade Windows to support WSL 2 - refer to this link.

Step 2 - Installing WSL 1

WSL 2 as of December 2020 is not the default version of installation - however it's the recommended one since it's the one with the real Linux kernel, and it's way faster than WSL 1. However, we need to install WSL 1 first then upgrade it to WSL 2.

Search for "Turn Windows features on or off" and click enter.

Search for "Turn Windows features on or off" and click enter.

Scroll down and make sure the "Windows Subsystem for Linux" is enabled. Then click on OK and restart your computer.

Step 3 - Updating to WSL 2

We can now update our WSL version from version 1 to 2. Open PowerShell as an administrator and run the following command:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart - This will enable the Virtual Machine feature which is required for WSL 2.

RESTART YOUR COMPUTER

Then, you need to download the Linux kernel update package from Microsoft, https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi. It's a very quick download and installation.

Now, you need to set WSL 2 as your default version of WSL. Run this from PowerShell as an administrator wsl --set-default-version 2.

Step 4 - Installing a Linux distribution

The recommended distribution for WSL 2 is Ubuntu. Ubuntu for WSL can be downloaded from the Microsoft Store.

Open Microsoft Store

Search for Ubuntu and install the latest one. (Just Ubuntu, without any versions). You may be asked to sign in to Microsoft, however this is not needed. (You may click on Not Now when prompted, then click install once again).

After Ubuntu is installed, search for it in the Start Menu and launch it.

You will be asked to enter your UNIX username (your choice) and pick a password for that user.

Ubuntu running within Windows.

To verify that your distro is running WSL 2, open cmd and type wsl -l -v, make sure the version is 2.

Congratulations! You have successfully installed WSL 2! πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰

For troubleshooting, consider visiting https://aka.ms/wsl2 which is the official Microsoft docs and tutorials for WSL.

Step 5 - Installing the Windows Terminal (optional but recommended)

The Windows Terminal is a new terminal from Microsoft which integrates with WSL automatically.

You just search for Windows Terminal from the Microsoft Store, then install it. Once installed, you may open your Ubuntu bash and use it normally. Windows Terminal automatically opens the /mnt/c/Users/<YOUR WINDOWS USER> which is your Windows user. For better performance and for a true Linux experience, we would want to tell Windows Terminal to open Ubuntu in /home/<YOUR LINUX USER> - to do that, click Ctrl + , or click on Settings, then add the following line to your Ubuntu entry:

That's it for installing and configuring Windows Terminal.

Step 6 - Miscellaneous configuration

# Fetches the package repository and upgrades all installed packages
sudo apt update && sudo apt upgrade -y

# Includes many tools for development (gcc, g++, clang)
# Also required for compiling pip packages from source if needed
sudo apt install build-essential

# Importing your SSH key from Windows (if exists) to WSL. Used for Git of course
mkdir ~/.ssh
cp /mnt/c/Users/<YOUR WINDOWS NAME>/.ssh/id_rsa ~/.ssh
chmod 400 ~/.ssh/id_rsa
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa

# Configuring Git
git config --global user.name "<YOUR NAME>"
git config --global user.email "<YOUR EMAIL>"

# Installing Python via pyenv (Python Version Manager)
# The recommended way to install Python, includes pip and other goodies
curl https://pyenv.run | bash
sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git # required for pyenv

# Add pyenv to your PATH.
echo "export PATH=\"$HOME/.pyenv/bin:$PATH\"" >> ~/.bashrc
echo "eval \"\$(pyenv init -)\"" >> ~/.bashrc
echo "eval \"\$(pyenv virtualenv-init -)\"" >> ~/.bashrc
source ~/.bashrc

pyenv doctor # MAKE SURE THERE ARE NO ERRORS

pyenv install 3.7.9 # we're using Python 3.7.9
pyenv global 3.7.9
python -m pip install --upgrade pip # upgrading pip, notice we're not using python3 or anything
# python just works fine because of pyenv

Step 7 - Configuring VSCode with WSL

Visual Studio Code works great with WSL - Windows handles the window itself yet the VSCode server is running over at WSL. To achieve that, open VSCode and install the WSL extension by Microsoft.

Then run code from WSL. You might need to reinstall some extensions that you had on Windows becuase they're not installed by default.

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