ROS 2 installation on WSL2
In this guide, you will learn how to install ROS 2 in the Windows Subsystem for Linux 2 (WSL2).
Table of Contents
Prerequisites
- Open a WSL2 terminal
-
You need to set the locale to
en_US.UTF-8
by running the following commands:sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8
1. Setup Sources
Add the ROS 2 apt repository to your sources list.
sudo apt update
sudo apt install software-properties-common curl gnupg2 lsb-release
sudo add-apt-repository universe
sudo apt update
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo ${UBUNTU_CODENAME:-${VERSION_CODENAME}})_all.deb"
sudo dpkg -i /tmp/ros2-apt-source.deb
rm /tmp/ros2-apt-source.deb
2. Install ROS 2 packages
Update the package list and install the ROS 2 packages.
sudo apt update
sudo apt upgrade
sudo apt install -y ros-humble-desktop ros-dev-tools ros-humble-rmw-zenoh-cpp
3. Environment setup
The .bashrc
is a text file located in your home directory (also indicated as ~
). It is an hidden file, since its name starts with a dot, that is executed each time you open a new terminal. Let’s set it up to activate ROS 2 in each new terminal.
-
Open the
.bashrc
file and add the following lines at the end. Use the commandnotepad.exe ~/.bashrc
to open the file in a text editor.source /opt/ros/humble/setup.bash source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
-
To test the installation, run the following command in a new terminal:
ros2 run demo_nodes_cpp talker
You should see the following output:
[INFO] [talker]: Publishing: 'Hello World: 1' [INFO] [talker]: Publishing: 'Hello World: 2' [INFO] [talker]: Publishing: 'Hello World: 3' and so on...
-
In another terminal run the following command:
ros2 run demo_nodes_py listener
You should see the following output:
[INFO] [listener]: I heard: [Hello World: 1] [INFO] [listener]: I heard: [Hello World: 2] [INFO] [listener]: I heard: [Hello World: 3] and so on...
If you see the above output, then the installation was successful.