ROS on WSL 2

ZIN MIN
7 min readMay 30, 2022

ROS stands for Robot Operating System, but it is not an OS what we know. ROS is just like a package library framework to develop a robot system easily. WSL stands for Windows Subsystem for Linux which can run in kernel level and we can operate from Windows OS level.

ROS support well on Ubuntu only. Last 3 years ago, we did ROS experiment on Ubuntu OS. As Windows guys, we need either a virtual machine or physical PC with Ubuntu OS to test ROS. Now WSL 2 solves this problem. We can use WSL 2 for ROS. It is quite fun!

Let’s start WSL 2.

First and foremost, I recommend to use Windows Terminal for this lesson. Windows Terminal is multi-tabbed terminal. You can download free from Windows App Store. Windows Terminal — Microsoft Store Apps

To install WSL in first time, you have to enable Windows Subsystem for Linux from Windows features list.

After WSL feature is installed, just type

WSL --install

After WSL 2 is ready, you can check available Linux OS to install by using following command.

WSL -l -o

-l for list and -o is online. Now you can see available Linux OS such as Debian, Kali-Linux, Ubuntu and so on.

In this lesson, I will use Ubuntu-20.04 to test latest ROS Noetic distro. See different ROS distro and Ubuntu version in Distributions — ROS Wiki page.

To install the specific Ubuntu version is very simple in WSL 2. Just type:

WSL --install -d Ubuntu-20.04

WSL 2 will launch a new terminal windows for your Linux OS. After installation is finished, you have to setup user name and password. Just enter the user name without space to avoid unnecessary issue. For me I put my name zinmin as user name. After user name, you have to set the password. After verify the password, Ubuntu OS is ready for us.

You can do some Linux command and explore Ubuntu OS via command line. Example type “cd /” to change to root directory and type “ls” to list down files and folders and root directory.

cd /
ls

If you want to explore inside etc folder from root directory.

ls /etc

WSL 2.0 can run Linux application with full GUI in Windows OS. To do that testing, we should install gedit application in Ubuntu, which is a useful application to edit the text file in Ubuntu.

Below command is installing gedit application. “sudo” means super user do. “apt install” is command to install application. “gedit” is application package name. “-y” mean yes to allow the system without verifying to install, otherwise system will get confirmation with Y/N to proceed for installation from you after checking the necessary packages. For the sudo command, you may need to type sudo user password.

sudo apt install gedit -y

Now you can test gedit GUI on windows. Type “sudo gedit text.txt” command. gedit will open the text editor with text.txt file name. If there is an existing file, gedit will open that file to edit.

sudo gedit text.txt

You can see the gedit text editor windows and you will notice penguin icon on windows task bar.

You can type something and click the save and close button as per usual windows application.

From the current windows, you can type “exit” command to logout from the Ubuntu OS terminal windows.

How to start Ubuntu OS again from WSL 2.0.

Just open Windows Terminal and type as below:

WSL -l -v

You can see which Linux OS are installed in your local and which are running or stopped.

To start the Linux OS, just type as below:

WSL -d Ubuntu-20.04

Default start director will be windows installation attached directory. We should type “cd ~” and change to Ubuntu login user directory.

cd ~

Before we start the ROS installation, we should do Ubuntu packages update and upgrade. I use both update and upgrade in single line command with && and put -y which means all upgrading process are agreed to installed, “yes”.

sudo apt update && sudo apt upgrade -y

This process will be taken 7 to 20 mins depend on your internet speed.

Ok. Next step is to do ROS setup on Ubuntu OS.

We will install ROS Noetic as per noetic/Installation/Ubuntu — ROS Wiki.

Step 1: Setup ROS in source.list

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Step 2: Set up your keys

First, install curl package

sudo apt install curl

Second, using curl and install the key

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

Step 3: Install ROS Noetic

Make sure Ubuntu packages are updated.

sudo apt update

Install ROS full desktop version. Desktop full version includes 2D/3D simulators and perception packages. It is suitable for learning environment. This installation process may take 10 mins to 30 mins depend on internet speed. “-y” is “yes” answer for verification of installation process to do direct installation without getting approval from you.

sudo apt install ros-noetic-desktop-full -y

Now ROS Noetic packages are already installed in Ubuntu-20.04. Next step is prepare the ROS environment setup.

Step 4: Setup the environment

Do ROS setup.bash file as source in Ubuntu .bashrc system file. In the below code, Linux “echo” command will write a text line inside ~/.bashrc file. Second line will define the current source to .bashrc file. Next time when start the Ubuntu OS, ROS setup.bash file will be defined as source.

echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

Step 5: Install dependency

After environment setup, next step is to install dependency for ROS packages to build. This installation may need 1 min to 5 mins depend on internet speed.

sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -y

Step 6: Initialize rosdep

Now we can start initialize the rosdep by using “rosdep init”.

sudo rosdep init

After rosdep initialization, you need to do rosdep update.

rosdep update

Yayyyyy!!!! ROS Noetic is ready now.

We can do Ubuntu environment checking with “printenv | grep ROS” commands. “printenv” command will write the environment variables. “grep ROS” command will filter out the environment variables which includes ROS keyword.

printenv | grep ROS

Now ROS Noetic on WSL 2.0 Ubuntu-20.04 environment is ready for your testing. You can review ROS/Tutorials — ROS Wiki and learn what is ROS from your windows PC.

--

--