How to Set Up a Secure Dev Environment on Windows 11 with WSL 2

How to Set Up a Secure Dev Environment on Windows 11 with WSL 2

WSL 2 — the Windows Subsystem for Linux — lets you run a real Linux system on Windows 11 without dual booting or a heavy virtual machine. For a developer, that means Linux tools and file permissions right next to your Windows apps. This guide installs WSL 2 the official way and locks it down — a dev environment holds your code, keys, and secrets.

Table of Contents (9)
  1. What WSL 2 is, and why developers use it
  2. What you need before you install
  3. Step 1: Install WSL 2 with one command
  4. Step 2: Update everything on day one
  5. Step 3: Lock it down — the security checklist
  6. Step 4: Set your memory and CPU limits
  7. Step 5: Install your dev tools the safe way
  8. Frequently asked questions
  9. The bottom line

What WSL 2 is, and why developers use it

WSL 2 runs a Linux distribution — usually Ubuntu — inside a lightweight utility virtual machine, with a real Linux kernel. The first version translated Linux system calls; WSL 2 runs the real thing, so it is faster for file-heavy work like npm install.

Developers use it because most servers run Linux: code that works in WSL 2 behaves the same on a Linux server, while your editor and Windows tools stay one click away. WSL 2 is the default for every new install.

What you need before you install

Check these first: Windows 11, any edition — WSL 2 works on Home as well as Pro (Windows 10 works from version 2004, build 19041, or later); hardware virtualization turned on in your firmware; a processor with SLAT — practically every Windows 11 PC qualifies; an administrator account; and internet access to download the engine, kernel, and distribution.

Step 1: Install WSL 2 with one command

Open PowerShell or Windows Terminal as administrator — right-click the Start button and choose Terminal (Admin) — then run:

wsl --install

That one command, documented on Microsoft Learn, enables the WSL and Virtual Machine Platform components, installs the latest Linux kernel, sets WSL 2 as the default, and installs Ubuntu. Restart the PC when it finishes. After you sign back in, an Ubuntu window asks you to create a Linux username and password — pick a real one.

Check you are on WSL 2 with wsl -l -v — the VERSION column should show 2. Want another distribution? List them with wsl --list --online, then install by name with wsl --install -d Debian. Move a WSL 1 distro with wsl --set-version <DistroName> 2.

Step 2: Update everything on day one

A fresh Ubuntu install is already out of date. Update it before you install anything else. Inside the Ubuntu terminal, run:

sudo apt update && sudo apt upgrade

Then update WSL itself from PowerShell with wsl --update. Make this a weekly habit — unpatched software is how old vulnerabilities survive.

Step 3: Lock it down — the security checklist

The install is done. Now the security work, which is the whole point of this guide:

  1. Use a normal Linux user, never root, for daily work. The account you created on first launch has sudo rights — stay in it. Running everything as root means one bad command can destroy the system.
  2. Give your SSH keys a passphrase. Generate a key with ssh-keygen, set a passphrase, and use ssh-agent so you type it once per session. Never copy your private key into a shared folder, a repo, or a chat window.
  3. Keep secrets out of your code. API tokens and passwords belong in environment variables or a secrets manager — never hard-coded in source files and never committed to Git. Add .env to your .gitignore on day one; if a secret ever reaches a public repo, assume it is stolen and rotate it.
  4. Keep Windows and Linux files apart. Work in the Linux filesystem (~/projects), not in /mnt/c/Users/... — files inside Linux are faster, and Windows folders stay out of reach.
  5. Let the firewall follow you. On Windows 11 22H2 and later with WSL 2.0.9 or later, Windows firewall rules apply to WSL through the Hyper-V firewall. Bind dev servers to localhost, not 0.0.0.0, so they are not reachable from your network.
  6. Get WSL only from official sources. WSL comes from the Microsoft Store or the microsoft/WSL releases page on GitHub; Ubuntu comes from the Store, wsl --install, or Ubuntu’s own releases. A random installer from a forum is a risk, not a shortcut.
  7. Shut it down when you are done. WSL keeps running after you close the terminal — run wsl --shutdown from PowerShell when you finish. A stopped environment cannot be attacked or eat your RAM overnight.

Step 4: Set your memory and CPU limits

By default, WSL 2 can use a large share of your RAM, which leaves Windows gasping when you run a database and a dev server together. Set a limit in a file called .wslconfig in your Windows user folder (C:\Users\<your name>\.wslconfig):

[wsl2]
memory=8GB
processors=4

On a 16 GB machine, 8 GB for WSL leaves Windows comfortable room; on 32 GB, 12 GB is reasonable. Save the file, run wsl --shutdown, and reopen Ubuntu.

Step 5: Install your dev tools the safe way

With the base secure, install what you actually use — Git first, then your language tools:

sudo apt install git

Set your Git identity, and check that Git sees your SSH key before your first push. Install Node.js, Python, or other runtimes from their official installers or version managers (such as nvm for Node.js), not from random scripts.

For editing, install the WSL extension in VS Code. Then, from inside your WSL terminal, type code . in your project folder: VS Code opens connected to WSL, with its terminal and debugger running on Linux while the window stays on Windows.

Frequently asked questions

Is WSL 2 safe to use for development?
Yes, when it is set up with care. The risks come from configuration, not WSL itself: an outdated distro, a root account doing daily work, secrets in code, or a dev server bound to the whole network.

Do I need Windows 11 Pro for WSL 2?
No. WSL 2 works on every Windows 11 desktop edition, including Home — you need an administrator account to install it, but no licence upgrade.

How much RAM should I give WSL 2?
On a 16 GB machine, 8 GB is a good limit; on 32 GB, 12 GB is reasonable. Set it in .wslconfig and restart WSL with wsl --shutdown.

Can I use VS Code with WSL 2?
Yes, and it is the recommended setup. Install the WSL extension, then open a project from the WSL terminal with code . — your editor runs on Windows while the code, terminal, and debugger run on Linux.

The bottom line

WSL 2 gives you a real Linux dev environment on Windows 11 with one command — wsl --install — but the install is only half the job. Update on day one, work as a normal user, protect your SSH keys, keep secrets out of your code, bind dev servers to localhost, and cap WSL’s memory in .wslconfig.

Sources:
– https://learn.microsoft.com/en-us/windows/wsl/install
– https://learn.microsoft.com/en-us/windows/wsl/setup/environment
– https://learn.microsoft.com/en-us/windows/wsl/compare-versions
– https://learn.microsoft.com/en-us/windows/wsl/wsl-config
– https://helpdeskgeek.com/install-wsl-linux-distro-windows-11-wsl-install/
– https://safeguard.sh/resources/blog/how-to-install-wsl-on-windows-11-safely
– https://www.linuxgeek.org/blog/how-to-enable-windows-subsystem-of-linux-in-windows-11/