Windows Subsystem for Linux (WSL) enables developers and programmers to experience a native Linux development environment right on a Windows machine. With each new version, WSL incorporates new and useful features to provide a full-fledged Linux experience within a Windows environment. For example, you can now run Linux GUI apps through WSL, which opens up infinite possibilities for Linux enthusiasts. Today, we're going to learn how to configure and set up a complete development environment in WSL. Depending on your preferences, you can make the necessary changes in this setup.
Even if you are not a hardcore programmer, installing and configuring WSL on your Windows machine will let you experience Linux and its features. Who knows, it'll make you switch to Linux, permanently.
If you have a working knowledge of the Linux command line environment, the configuration steps will be a cakewalk for you. If not, you can still do it through the easy step-by-step instructions given below.
Prerequisites for WSL Setup
Let's quickly take a look at the prerequisites to ensure you meet the minimum requirements for this setup.
- Windows 10 (version 2004 or higher), or Windows 11
- Virtualization must be enabled in the BIOS. Check the status in Task Manager → Performance → CPU section.
📷 Make sure CPU virtualization is enabled - At least 8GB of RAM
Ample RAM is essential for any virtualized application to ensure smooth and glitch-free operation.
Step 1: Enable WSL and Install Ubuntu
First, we'll enable WSL on our Windows machine and install Ubuntu Linux on it. The process may take some time, but it is simple. Here are the step-by-step instructions.
- Invoke the command prompt or PowerShell instance with administrative privileges and run the following command in it.
wsl --install - By default, it will automatically install the Ubuntu distribution on WSL. If you want another Linux distro, you can use the following commands to choose your preferred one from the list.
wsl --list --online wsl --install -d <DistributionName> - After the installation is completed, you'll be prompted for the username and password. Choose your preferred username with a strong password to complete the installation process.
To get the best experience, use WSL in the Windows Terminal application.
Step 2: Update Your System
Once the initial installation phase is complete, it's time to update all the installed packages on your fresh Ubuntu instance. To do that, use the following command.
sudo apt update && sudo apt upgrade -y
It may take several minutes to complete this process. Updating the system ensures all the security patches have been applied and all the installed packages have been updated to their latest version.
Step 3: Install Git and Configure Version Control
Start with installing the most essential tool you'll need in any project, regardless of the tech stack you are using. And that's it! Let's see how to install and configure it.
sudo apt install git -y
After the installation completes, configure Git identity on your system.
git config --global user.name "Your Full Name"
git config --global user.email "your.email@address.com"
To ensure added security for your Git commits, add a public SSH key to your GitHub account. To do that, first generate the SSH key pair as follows:
ssh-keygen -t ed25519 -C "your.email@address.com"
Now, copy the public key from the ~/.ssh/id_ed25519.pub file.
Log in to your GitHub account and go to the Settings → SSH and GPG keys option. Click the New GPG key button and add the copied public key.
Step 4: Install Node.js and npm
If you are a web developer, chances are that you are using Node.js regularly. Let's install it first. To do that, first, we'll install Node Version Manager (nvm), which eases Node.js version management.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/<Version Number>/install.sh | bash
Replace <Version Number> with the current stable release's semantic version number.
Reboot and restart your WSL instance and install Node.js as follows:
nvm install --lts
nvm use --lts
After installation, do not forget to verify it through the following commands:
node --version
npm --version
If you have never worked with Node.js, you can skip this step.
Step 5: Set Up Python Development Environment
Fortunately, Ubuntu has Python 3 preinstalled, saving you time to get it from the relevant package repos. But, pip and other tools need to be installed as well to complete the entire setup.
sudo apt install python3-pip python3-venv -y
To manage dependencies like a pro, you need to install pipenv as well.
pip3 install --user pipenv
Finally, you must add the pip directory location to the PATH environment variable.
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
After completing the Python setup, let's move on to the next step.
Step 6: Install Docker for Containerization
No modern dev workflow is complete without Docker. That's how we develop, test, build, and release modern applications. Let's install it right away.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
The next important step is to add your current user to the docker group. It'll ensure you don't have to prepend sudo to the docker commands every day.
sudo usermod -aG docker $USER
After firing this command, log out and log in so that the group change can take effect. Finally, verify the Docker installation to ensure everything is working fine.
docker --version
docker run hello-world
Make sure you have ample RAM on your Linux system to use this feature.
Step 7: Install and Configure Zsh with Oh My Zsh
If you are using the good old bash shell, consider upgrading to Zsh, further enhanced with Oh My Zsh. It gives you auto-completion of commands, a colored interface, a better Git prompt, and much more.
Here's how to install and configure it:
sudo apt install zsh -y
After installing Zsh, it's time to install and configure Oh My Zsh.
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
And lastly, make sure to make Zsh your default shell.
chsh -s $(which zsh)
After all these steps are complete, restart the shell for everything to take effect. There are dozens of Zsh plugins you can install to further add more features and functions to the shell.
Step 8: Set Up Code Editors
Next comes the setup of a code editor. The best option is to first install Visual Studio Code on Windows and then install the WSL extension within the code editor.
Now you can access Visual Studio Code directly from within WSL through the following command.
code .
If you prefer a command-line environment, go for the Neovim editor. Here's how to install and configure it:
sudo apt install neovim -y
Optionally, you can also create an alias for easy and quick access.
echo 'alias vim=nvim' >> ~/.zshrc
source ~/.zshrc
Helix Editor is another powerful code editor you can try out. I've tested it for my C projects, and it worked like a charm.
Step 9: Database Setup
No matter which tech stack you are using, if you are into hardcore backend development, you are going to use a DBMS for your projects. Let's install two of the most popular database solutions.
Let's first install and configure PostgreSQL to have a reliable and stable DBMS option.
sudo apt install postgresql postgresql-contrib -y
After installation, start the database service.
sudo service postgresql start
Lastly, create a database user to get started.
sudo -u postgres createuser --interactive
If you are project is not huge, I'll recommend installing SQLite as well.
sudo apt install sqlite3 -y
Although MySQL is another popular option, the two mentioned above are lightweight and easy to maintain.
Step 10: Configure File System Access
Although you can easily access Windows drives and directories from within WSL, I'd recommend creating projects in the WSL environment for better performance.
But, if you still want to access Windows drives, they are mounted under /mnt/ mount point. The Windows system drive C: is accessible through the /mnt/c/ path.
If you want to access any folder on the C: drive, the best way is to create a symbolic link to that folder. Here's an example:
ln -s /mnt/c/Users/YourWindowsUsername/Documents/Projects ~/win-projects
For local projects, use your account's home directory.
Step 11: Environment Variables and Shell Configuration
To get a better shell experience that aids in your development workflow, edit the ~/.zshrc file to add the necessary aliases and environment variables.
# First, open the file
nano ~/.zshrc
And the following rules and directives in this file.
# Development aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
# Git shortcuts
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git pull'
# Docker shortcuts
alias dps='docker ps'
alias dpa='docker ps -a'
alias di='docker images'
# Environment variables
export EDITOR=nvim
export PATH="$HOME/.local/bin:$PATH"
Feel free to modify the aliases as per your preferences.
Step 12: Customize WSL Configuration
If you have a high-end system configuration and dedicate a fair slice of system resources for WSL, you can do it through the C:\Users\WindowsUserName\.wslconfig file.
Here's an example entry for WSL configuration.
[wsl2]
memory=16GB
processors=8
swap=4GB
localhostForwarding=true
Depending on the hardware configuration of your PC, you can tweak and adjust these values. It'll ensure you get better performance when working in a WSL environment.
In case you are not sure what you are doing, you can skip this step.
Step 13: Use Custom DNS Servers (Optional)
If you want to use custom DNS servers for your WSL instance, you can do so easily by editing the /etc/resolv.conf file. First, open this file in your preferred text editor.
sudo nano /etc/resolv.conf
Then add your custom DNS servers. An example is shown below.
# Google DNS servers
nameserver 8.8.8.8
nameserver 8.8.4.4
If your Windows DNS servers are the ones you want to use, you can skip this step altogether.
Wrapping it Up
This setup provides you with a professional-grade development environment that combines the best of Linux tooling with Windows integration.
Whether you're building web applications, working with containers, or managing infrastructure, your WSL environment is equipped to handle the demands of modern software development.