Use VS Code on WSL? Setup & Fixes
In this article
Yes, you can use Visual Studio Code on Windows Subsystem for Linux (WSL), and the recommended way is to install the Windows version of VS Code and connect it to WSL using the official “WSL” extension. This gives you a full Linux development environment (bash, compilers, tools) while keeping the familiar VS Code interface on Windows, without needing a separate Linux GUI.
Why Use VS Code with WSL?
WSL lets you run a real Linux kernel and userland on Windows. Many developers need Linux for tools like Python, Node.js, Docker, or GCC that behave differently on Windows. Rather than switching between a Windows editor and a Linux terminal, VS Code’s WSL extension bridges the two. You edit files in a Linux directory, run commands in a Linux terminal, and use Linux-specific extensions (like Python or Remote-SSH) — all from the same window.
The key benefit is that your code executes in Linux, not Windows. For example, if you install a Python package with pip inside WSL, it’s available to the VS Code Python extension because the extension runs on the WSL side. This avoids the classic “works on my machine” problem caused by environment differences.
How It Works: Remote Development Architecture
VS Code uses a client-server model. The Windows app is the client (the UI). The WSL extension starts a small “VS Code Server” inside your Linux distribution. The server handles file access, terminal, debugging, and language services. The client sends UI commands over a local socket. This is the same architecture used for SSH and Containers, so it’s well-tested.
When you open a folder in WSL, VS Code automatically installs the server in ~/.vscode-server on first use. Extensions you install while connected to WSL are installed on the Linux side, not on Windows. Extensions that affect the UI (like themes) stay on Windows. This separation is automatic and usually invisible.
Setting Up VS Code for WSL
Here are the steps to get started. You need Windows 10 version 2004 or later (or Windows 11), and WSL2 enabled.
- Install WSL (if not already): Open PowerShell as Administrator and run
wsl --install. This installs WSL2 and a default Linux distribution (usually Ubuntu). Restart if prompted. - Install VS Code on Windows from the official site. Choose the User Installer (not System) for faster updates.
- Install the WSL extension in VS Code. Search for “WSL” in the Extensions view (Ctrl+Shift+X). The publisher is Microsoft.
- Open a WSL window: Press
Ctrl+Shift+P, type “WSL: New Window”, and select your distribution. Or from a WSL terminal, runcode .to open the current folder. - Trust the folder when prompted. VS Code will download the server and connect.
Once connected, you’ll see “WSL: Ubuntu” (or your distro) in the bottom-left corner of the status bar. That’s your indicator that you’re in Linux mode.
Choosing Between WSL and Native Linux
WSL is not a full Linux desktop. It’s a command-line environment with optional GUI support (WSLg on Windows 11). If you need a graphical Linux desktop (like GNOME or KDE), you’re better off with a virtual machine or dual boot. But for coding, WSL is often faster and more convenient because it shares the Windows file system and GPU.
For web development, Python, or system programming, WSL is usually sufficient. If you’re doing heavy machine learning or need a dedicated Linux server, consider a VM or cloud instance. WSL also has a small overhead, but it’s much lighter than a full VM.
Common Problems and Fixes
Here are frequent issues and how to resolve them:
- “WSL not found” error: Make sure WSL is installed and you’ve rebooted after
wsl --install. Runwsl --statusin PowerShell to check. - VS Code server won’t start: Try deleting the
~/.vscode-serverfolder in WSL and reopening. Also check your firewall or proxy settings. - Extensions not working: Extensions must be installed on the WSL side. Click the “Install in WSL” button if available, or reinstall the extension while connected.
- File permission errors: If you edit files in the Windows file system (e.g.,
/mnt/c/), you may hit permission issues. Keep your code in the Linux file system (~/projects) for best performance and fewer problems. - Slow performance: Accessing files under
/mnt/cis slow because of the 9P protocol. Move your project to the Linux home directory.
Performance Tips and Best Practices
To get the most out of VS Code + WSL:
- Store your code in the Linux file system (e.g.,
~/code), not in/mnt/c. - Use the built-in terminal (Ctrl+`) to run Linux commands directly.
- Install extensions that are Linux-specific, like Python or Node.js, while connected to WSL.
- For large projects, consider disabling file watchers or increasing the
files.watcherExcludesetting to reduce CPU usage. - If you use Git, set your line endings to
LFto avoid warnings.
Alternatives to VS Code + WSL
If VS Code + WSL doesn’t suit you, consider:
- VS Code Remote-SSH: Connect to a Linux server or VM. Good if you need a real Linux environment.
- JetBrains IDEs: IntelliJ, PyCharm, etc. support WSL via a remote interpreter, but setup is more manual.
- Vim/Neovim: Run entirely in WSL terminal. Lightweight but steep learning curve.
- Windows Native: If your project doesn’t need Linux, just use Windows tools. Simpler but may cause cross-platform bugs.
Frequently Asked Questions
Do I need to install VS Code inside WSL?
No. You install VS Code on Windows and use the WSL extension. The extension automatically handles the server inside WSL. Installing the Linux version of VS Code is not recommended because it requires a GUI and is less integrated.
Can I use WSL without the extension?
Yes, you can use the WSL terminal directly and edit files with any editor, but you lose the integrated debugging, IntelliSense, and terminal features that make VS Code powerful. The extension is free and official.
Why is my project slow when it’s on /mnt/c?
Accessing Windows drives from WSL uses a network-like protocol (9P) which is slower than the native Linux file system. Move your project to ~/ to get near-native performance.
Can I run Docker from VS Code in WSL?
Yes. Install Docker Desktop with WSL2 integration, then use the Docker extension in VS Code. The extension will communicate with Docker running in WSL.
How do I update the VS Code server in WSL?
VS Code updates the server automatically when you open a WSL window. If it gets stuck, close all WSL windows, delete ~/.vscode-server, and reopen.
Is WSL free?
Yes, WSL is a free component of Windows. The Linux distributions (like Ubuntu) are also free. VS Code is free for personal and commercial use.