How to Get Started With ROS2 in WSL on Win10/Win11?

by shaalekh in Circuits > Robots

26 Views, 0 Favorites, 0 Comments

How to Get Started With ROS2 in WSL on Win10/Win11?

Gemini_Generated_Image_jmzb33jmzb33jmzb (1).png

In this tutorial, we'll set up ROS2 Humble development environment on a Windows PC. Following the ROS2 Humble installation for Windows is very hectic, and you have to go through rigmarole. Here is a better way to do it. You can choose any OS distro and ROS2 distro while installation, but ROS2 distro have their OS they go with. Like ROS2 Humble will go with Ubuntu-22.04 LTS and ROS2 Jazzy will go with Ubuntu-24.04 LTS.

We are going to set up the following things:

  1. VS Code
  2. WSL with Ubuntu22LTS
  3. ROS2
  4. GUI Interface (For Windows10)

Supplies

  1. Stable Internet Connection
  2. A Windows PC (10/11)
  3. Minimum 8GB RAM in your computer
  4. Multi-core processor (sounds better)

Install WSL2

  1. Check whether WSL is pre-installed in your system. Open Command Prompt.
wsl --status
  1. If return "command not found", it means WSL is not present and you have to install it. To install run,
wsl --install
  1. then check the version by running the command in Step 1. If the version is 2, good. If version is 1, run,
wsl --set-default-version 2
  1. Download the Linux Distribution. For ROS2 Humble, we're going to install Ubuntu 22 LTS.
wsl --install -d Ubuntu-22.04
#or run this it gets stuck at 0%
wsl --install --web-download -d Ubuntu-22.04
  1. Note: In case this fails, install from Microsoft Store. Go to MS Store > Search> Ubuntu 22 LTS> Install.

Setup Ubuntu and ROS2

  1. Believe in what you are doing.
  2. Open the Command Prompt
  3. Run,
wsl
  1. Follow the installation process-- add a username and set a password.
  2. Remember the password.
  3. You'll see something like: username@host-name:~$
  4. Now inside the Ubuntu, run
sudo apt update
sudo apt upgrade
  1. Now install the ROS2 Humble. Follow the installation instruction given on the official website.
  2. Under Install ROS Packages , go with the
sudo apt install ros-humble-desktop
  1. After the installation is completed, run this command
cd ~
echo "source /opt/ros/humble/setup.bash" >> .bashrc
  1. Restart the terminal and open wsl again.

Install VS Code

Screenshot 2025-12-26 122653.jpg
  1. Open Browser
  2. Visit code.visualstudio.com
  3. Click on the Download Icon as directed in the image above.
  4. Open the .exe file and follow the installation process.

Link VSCode With WSL

Screenshot 2025-12-26 142926.jpg
  1. Open VSCode from windows start menu.
  2. Go to Extenstions and install the following plug-ins:
  3. Python [Microsoft]
  4. Pylance [Microsoft]
  5. Python Debugger [Microsoft]
  6. Python Environments [Microsoft]
  7. WSL [Microsoft]
  8. C/C++ Extension Pack [Microsoft]
  9. After all of them are installed, restart the VSCode.
  10. On the Side Bar, open Remote Explorer.
  11. Under Remote Explorer, you'll find WSL Target. There, click on the plus sign to add distro.
  12. It will automatically detect the WSL in the system. In this case, select Ubuntu-22.04 LTS.
  13. Wait for few minutes, it will automatically perform the next installation steps.

Setup X-server for GUI Applications (for Win10 Only)

In WSL Windows 10, you can't run GUI application directly through terminal. You need and x-server to run GUI applications through terminal. This feature is provided in Windows 11, but on Win10 we have to set it up on our own. So here are the steps to get that on your PC.

  1. Open browser and go VcXsrv Windows X-server
  2. Install it.
  3. Go to the Windows Start Menu > XLaunch.
  4. The Display Settings window will appear, change nothing and just go next.
  5. Under Select how to start clients, change nothing and go next.
  6. Under Extra Settings, uncheck Native opengl and check Disable access control.
  7. Click Next and Finish.

Now, we'll connect the Ubuntu to X-server.

  1. Open Command Prompt and run wsl.
  2. Run this command
cd ~
echo "export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0" >> .bashrc
echo "export LIBGL_ALWAYS_INDIRECT=1" >> .bashrc
  1. Restart the wsl terminal or just run this command
cd ~
source .bashrc


Now test by running a GUI app:

  1. Run this command
sudo apt install x11-apps
  1. Run the app
xclock
  1. Check if a new window has appeared portraying clock. If yes your gui is working.

Final Working Test

Screenshot 2025-12-26 152352.jpg

Now we'll open a ROS2 workspace folder in VSCode.

  1. Open Command Prompt and run wsl.
  2. Create a directory ros2_ws and sub-directory src by running
mkdir ros2_ws/src -p
  1. Create a ros2 package named my_pack in src. Please check out the tutorial on the official website for more information regarding workspace and packages.
cd ros2_ws/src
ros2 pkg create my_pack --built-type ament_python --dependencies rclpy std_msgs
  1. Now, open VSCode from src directory.
code .
  1. Voila! You are good to go.