WSL 2 setup for devs
Last updated: Dec 15, 2024
After having used a Mac environment/Linux VMs previously at my work, Windows Subsystem for Linux (WSL) has been a game changer for me to develop on Windows. It allows me to run a full Linux environment natively on Windows, without using a virtual machine or a dual boot. It provides the best of both worlds, where one can run windows apps (VSCode, Chrome etc.) alongside Linux CLI tools (bash, git, vim etc.). It's fast and lightweight, shares resources/filesystem with Windows - allowing you to work seamlessly without having to fiddle with compatibility layers.
In this guide, I'm sharing how I set up my WSL V2 with Ubuntu and development environment for Python, Rust, Node, React, etc.
Install Ubuntu using WSL 2
Enable WSL V2
- I use Windows 11, where I can use WSL out of the box.
Check your windows version using below in the Terminal/PowerShell
winverInstall WSL manually if lower than 10.
- Open
Terminal/PowerShelland ensure WSL version is V2.
wsl --statusThis should return the default version as 2.
Install Ubuntu
- Install Ubuntu using following commands in
Terminal/PowerShell, you will be asked to input a username and password for your linux account, input those accordingly:
wsl --install -d Ubuntu-24.04This installs WSL 2 with Ubuntu 24.04 (Replace with the latest/desired Ubuntu version). If not, you can manually install it from the Microsoft Store.
Confirm Installation
wsl --list --verboseMake sure Ubuntu is listed and running under WSL 2.
If installed successfully, you should also see Ubuntu 24.04.01 LTS option in terminal (click on dropdown box on right of the tab names). You can go to terminal > settings & set the default profile to Ubuntu 24.04.01 LTS - which will open the ubuntu by default on terminal.
Install zsh, ohmyzsh
zsh
- Install zsh using package manager
sudo apt update && sudo apt upgrade -y
sudo apt install zsh- Verify installation
zsh --version- Make it your default shell
chsh -s $(which zsh)ohmyzsh
- Install ohmyzsh using curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)Plugins
- Fetch autosuggesions, zsh-syntax-highlighting, zsh-fast-syntax-highlighting, zsh-autocomplete plugins
git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && \
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting && \
git clone --depth 1 https://github.com/marlonrichert/zsh-autocomplete.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autocomplete- Add plugins to .zshrc
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
fast-syntax-highlighting
zsh-autocomplete
)- Reload your environment to make changes work
source ~/.zshrcUpdate & setup Ubuntu Packages
sudo apt update && sudo apt upgrade -yInstall common tools, including dependencies for pyenv, protobuf etc.:
sudo apt install \
keychain \
build-essential \
protobuf-compiler \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
curl \
file \
git \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
justInstall Python
Ubuntu usually comes with Python pre-installed. Verify version:
python3 --versionFor Python version management, install pyenv:
- Clone pyenv in the ~/.pyenv directory
- Install the python versions you need, for example
pyenv install 3.13.1Install Rust
Use the official Rust installer:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/envCheck installation:
rustc --version
cargo --versionInstall Node.js, npm, yarn
Use Node Version Manager (nvm) for flexibility:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts- Verify the versions:
node -v
npm -vInstall Yarn
- Using the official Yarn APT repo:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn -y- Check version:
yarn -v