ROS 2 Setup Guide

An exhaustive guide for installing a ROS 2 development environment

View project on GitHub

Home

ROS2 installation on Ubuntu

In this guide, you will learn how to install ROS2.

Table of Contents

Prerequisites

  • Open a terminal
  • check locale settings by running locale command in the terminal. The output should be similar to the following: locale
  • If the output is not en_US.UTF-8, 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 curl gnupg2 lsb-release
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'

2. Install ROS 2 packages

Update the package list and install the ROS 2 packages.

sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop
sudo apt install ros-dev-tools

3. Environment setup

Source the ROS 2 setup script to add ROS 2 environment variables to your shell session.

echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc
source ~/.bashrc

To test the installation, run the following command:

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.

4. References