Skip to content

Lab 3.0. ROS 2 Installation

Estimated time to complete this lab: 30 minutes

Objectives

At the end of this self-learning lab, you should be able to:

  • use ROS 2 Jazzy on your Ubuntu 24.04 installation

Before working on this lab, you should have a Ubuntu 24.04 environment ready because we are going to install ROS 2 inside Ubuntu. If you still haven't install Ubuntu 24.04, you can refer to 2. Linux Installation

Main official ROS 2 installation instructions: Ubuntu install of ROS 2 Jazzy and Installation troubleshooting. Visit the official link for more detail or when facing problems.

0. System setup

Make sure you have a locale which supports UTF-8 encoding.

locale  # check for UTF-8, if the output showing `UTF-8` in each entry, you can skip the following few steps

sudo apt update && sudo apt install locales
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

locale  # verify settings

1. Configure your Ubuntu repositories:

By default, your Ubuntu repositories should allow "restricted," "universe," and "multiverse."

# To check or to configure, you can
sudo add-apt-repository restricted
sudo add-apt-repository universe
sudo add-apt-repository multiverse
sudo apt update

2. Set up installation keys

sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update

3. Install ROS 2 via apt

sudo apt update && sudo apt install -y ros-dev-tools ros-jazzy-desktop-full

4. Environment setup

You must source the /opt/ros/jazzy/setup.bash script in every bash terminal you use ROS 2 in. It can be convenient to automatically source this script every time a new shell is launched. The following command will do that for you. You only need to run this command once.

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

Note

~/.bashrc is a file that is run once automatically every time you create a new bash terminal (e.g. via Ctrl+Alt+T) See Linux tutorials :: Shell utilities for more information.

5. Workspace setup

Code in ROS 2 is placed inside a ROS 2 workspace. Run the following commands to set up a workspace under ~/ros2_ws. Note that we also need to source our workspace setup.bash file whenever we start a new terminal. We can automate this step by putting this command inside ~/.bashrc file, similiar to what we did before.

mkdir -p ~/ros2_ws/src && cd ~/ros2_ws/ && colcon build
echo "source ~/ros2_ws/install/setup.bash" >> ~/.bashrc && source ~/.bashrc

6. Verify installation by running a demo

In one terminal, run a C++ talker:

ros2 run demo_nodes_cpp talker

In another terminal, run a Python listener:

ros2 run demo_nodes_py listener

You should see the talker saying that it's Publishing messages and the listener saying I heard those messages. This verifies both the C++ and Python APIs are working properly.

Completion

Great! You have successfully installed ROS 2!

Reference

Ubuntu install of ROS 2 Jazzy

Installation troubleshooting