Hey there! π If you're looking to set up Ubuntu on your Windows machine using WSL (Windows Subsystem for Linux), I've got you covered. I recently went through this process myself, and I want to share my experience to make it easier for you.
What We'll Be Doing
We'll install Ubuntu using WSL on Windows, get it properly configured, and connect it to VS Code. Once this is set up, you'll have an awesome development environment that gives you the best of both Windows and Linux.
Getting Started
First things first, you'll need:
- Windows 10 or 11 with WSL2 enabled
- VS Code installed on Windows
- A bit of patience (and maybe some coffee β)
The Installation Process
Installing Ubuntu with WSL is quite straightforward:
- Open PowerShell as administrator and run:
wsl --install -d Ubuntu
Alternatively, you can install Ubuntu from the Microsoft Store
Launch Ubuntu from the Start menu after installation completes
Set up your username and password when prompted
Setting Up VS Code Remote Access
This is where the magic happens! We're going to set up VS Code so you can work on your Ubuntu system from the comfort of your Windows VS Code setup.
- First, find your Ubuntu IP address:
ip addr
Look for the eth0
section and note down the IP address.
In VS Code on Windows, install the "Remote - SSH" extension.
Here's the important part - we need to set up the SSH config. Press
Ctrl + Shift + P
, type "Remote-SSH: Open Configuration File" and add this:
Host ubuntu-wsl
HostName your_ubuntu_ip_address
User your_username
RemoteCommand /bin/bash
RequestTTY force
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
ForwardX11 yes
ForwardX11Trusted yes
(Don't forget to replace your_ubuntu_ip_address
and your_username
with your actual details!)
- Now you can access your Linux environment with all the power of VS Code's features!
Behind the Scenes: What's Actually Happening
What's cool about this setup is that Windows creates a virtual network that allows VS Code to SSH into the WSL Linux instance as if it were a separate machine, while everything actually runs locally on your computer.
This gives you the best of both worlds - Windows UI with Linux development environment, without the overhead of a traditional virtual machine or dual-boot setup.
Connecting Everything
Now for the moment of truth! In VS Code, hit Ctrl + Shift + P
again, type "Remote-SSH: Connect to Host" and select your Ubuntu setup. If everything's set up correctly, you should be able to connect!
Troubleshooting
If things aren't working quite right:
- Double-check your IP address - these can sometimes change
- Make sure SSH is running:
sudo service ssh status
- Check your firewall settings
- Try restarting VS Code (yes, sometimes the classic "turn it off and on again" actually works!)
You're All Set!
That's it! You now have a fully functioning Ubuntu setup accessible right from VS Code. Pretty cool, right? Feel free to customize it further to match your workflow.
Wrapping Up
This setup has completely transformed my development workflow. I can now easily switch between Windows and Linux environments without the hassle of rebooting or dealing with slow VMs.
Happy coding! π
Top comments (0)