DEV Community

Haripriya Veluchamy
Haripriya Veluchamy

Posted on • Edited on

Setting Up Ubuntu Linux on Windows: A Developer's Guide

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:

  1. Open PowerShell as administrator and run:
   wsl --install -d Ubuntu
Enter fullscreen mode Exit fullscreen mode
  1. Alternatively, you can install Ubuntu from the Microsoft Store

  2. Launch Ubuntu from the Start menu after installation completes

  3. 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.

  1. First, find your Ubuntu IP address:
   ip addr
Enter fullscreen mode Exit fullscreen mode

Look for the eth0 section and note down the IP address.

  1. In VS Code on Windows, install the "Remote - SSH" extension.

  2. 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
Enter fullscreen mode Exit fullscreen mode

(Don't forget to replace your_ubuntu_ip_address and your_username with your actual details!)

  1. 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)