Getting Started with ROS2: Install and Setup ROS2 Humble on Ubuntu 22.04(LTS)

Part 3 of our “Getting Started with ROS2” Series

Sagar Kumar
Spinor
6 min readMay 15, 2024

--

Welcome, fellow readers, to our series “Getting Started with ROS2”! In this series, we aim to provide you with a comprehensive introduction to ROS 2 and will guide you through the fundamentals, its key concepts, and practical applications. If you have never used the Robot Operating System(ROS) before, even ROS 1, or if you want a practical and quick refreshment of the basics then this series is for you. Feel free to explore the links provided for a more in-depth understanding of the concepts discussed.

Here are the articles in the series:

  1. Getting Started with ROS2: An Introduction
  2. Getting Started with ROS2: Why ROS2?

In our first article, “Getting Started with ROS2: An Introduction”, we laid the groundwork by introducing you to the basic concepts of ROS 2. In our second article, “Getting Started with ROS2: Why ROS2?”, we dig deeper into the rationale behind using ROS 2. Now, in our third article, we will guide you through the installation and setup process of ROS 2. So let’s get started!

Can I install ROS2 on my system?

To install ROS 2, you have several options. ROS 2 provides binary packages for certain OS. The official ROS 2 installation documentation calls them Tier 1 operating systems, making installation straightforward for users of these operating systems.

  1. Ubuntu Linux (Debian)
  2. Red Hat
  3. Windows

Important Notes:

  • For macOS users, the process is a bit different. ROS 2 does not provide binary packages for macOS, so installation requires building from the source. While this can be a more involved process, it allows macOS users to use ROS 2 on their systems.
  • For Raspberry Pi, try to install ROS 2 on Raspberry Pi 3 or the above models. For the safer side, use the 64-bit Debian-12-based OS. Like Raspberry Pi OS, Ubuntu, or Ubuntu Mate. Follow this link to install ROS 2 on Raspberry Pi.
  • Both binary packages and building from source result in a fully functional ROS 2 install, with differences based on your usage needs.
  • Installing from packages is recommended for automatic dependency management and updates alongside system updates, but requires root access.
  • If you lack root access, consider the binary archive.

Can I install ROS 2 using a container solution like Docker?

Another convenient way to set up ROS2 is by using Docker. Docker allows you to run ROS2 in a containerized environment, which can simplify the setup process and ensure consistency across different systems.

To install ROS2 using Docker, you’ll first need to install Docker on your system. Once Docker is installed, you can pull the ROS2 Docker image from the official ROS Docker Hub repository. From there, you can create a new Docker container running ROS2 and start developing within the container.

Using Docker for ROS2 development can be particularly useful when you want to isolate your ROS2 environment from the rest of your system or when you need to quickly set up ROS2 on a new machine without going through the full installation process.

Things to check before installation

  • When installing ROS 2, it’s recommended to install the Long-Term Support (LTS) version, as it provides a stable foundation for your development.
  • Before installation, it’s crucial to check the compatibility of the ROS 2 version with your operating system version. This information can be found in the official documentation of the ROS 2 version you intend to install. Ensuring compatibility will help prevent any issues that may arise from mismatched versions.
  • Moreover, it’s important to verify the compatibility of your Gazebo version with the ROS 2 version you intend to install. You can verify it here.

What OS + ROS 2 combination should I choose?

If you’re wondering which operating system to choose, Ubuntu is often recommended for ROS 2 development. Ubuntu Mate, in particular, is a great choice as it can also be installed on Raspberry Pi and it’s lightweight. This means that your Desktop Computer (ground control or simulation testing station) can have the same OS as your Raspberry Pi (Robot Computer), simplifying compatibility and ensuring a smoother development experience.

In this article series, we will use the Ubuntu Mate — Jammy Jellyfish (22.04) with ROS 2 Humble Hawksbill (LTS) combination. This will provide a stable and well-supported environment for readers to follow along with our tutorials. So, without further ado let's start the installation process. You can check the official documentation of ROS2 Humble installation on Ubuntu.

Following are the steps to install ROS 2 Humble on Ubuntu 22.04(LTS)

1. Set locale

locale  # check for UTF-8

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

2. Setup Sources

To add the ROS 2 apt repository, ensure the Ubuntu Universe repository is enabled.

sudo apt install software-properties-common
sudo add-apt-repository universe

Add the ROS 2 GPG key with apt.

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

Then add the repository to your sources list.

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

3. Install ROS 2 packages

After setting up the repositories, update your apt repository caches. This ensures your system is up to date before installing ROS 2 packages.

sudo apt update
sudo apt upgrade

Now there are two options for ROS 2

Desktop Install (Recommended):

  • Includes ROS, RViz, demos, and tutorials.
  • Provides a complete desktop environment for ROS development.
sudo apt install ros-humble-desktop

ROS-Base Install (Bare Bones):

  • Includes communication libraries, message packages, command line tools.
  • Does not include GUI tools, suitable for minimalistic setups.
sudo apt install ros-humble-ros-base

We will install the “ros-humble-desktop” on the Ground Control and Simulation System(our Desktop/Laptop) and the “ros-humble-ros-base” on the Robot Computer(Raspberry Pi).

Finally, install the Development tools: Compilers and other tools to build ROS packages.

sudo apt install ros-dev-tools

4. Environment setup

To start working on ROS 2, first, you need to source the setup script in each terminal session.

# Replace ".bash" with your shell if you're not using bash
# Possible values are: setup.bash, setup.sh, setup.zsh
source /opt/ros/humble/setup.bash

5. Try some examples

NOTE: The examples are only included in the “Desktop Install”.

Talker-listener

In one terminal, source the setup file and then run a Python talker:

source /opt/ros/humble/setup.bash
ros2 run demo_nodes_py talker

In another terminal source the setup file and then run a Python listener:

source /opt/ros/humble/setup.bash
ros2 run demo_nodes_py listener

How it looks like:

talker-listener demo scripts

Stop both scripts using Ctrl+C.

6. Bonus step!

To automate the environment setup process and avoid sourcing the setup file manually each time, we can add the command to source the setup file in the “.bashrc” file. This way, the command will be executed automatically every time we open a new terminal or SSH session.

this is how we can edit the .bashrc

nano ~/.bashrc

and add the command `source /opt/ros/humble/setup.bash` in the end of the file.

edit .bashrc and add the source command

What’s next?

In the next article, we will discuss the concepts such as workspaces and nodes. Workspaces are essential for organizing and building ROS 2 packages, while nodes are the individual processes that perform computation in ROS 2. Understanding these concepts will be crucial as we progress in our journey with ROS 2 development.

If you’ve made it this far, it means you’re not just interested — you’re committed, and we’re delighted to have you here!

Your interest and engagement inspire us to create more content and share knowledge with fellow learners, the community of robotics, and tech enthusiasts who share our passion.

So, thank you for being a part of this journey with us. Stay tuned for more insightful articles, tutorials, and practical examples as we continue our exploration of ROS 2 together.

Additional Reading

--

--

Sagar Kumar
Spinor
Editor for

Sagar is a computer vision and robotics expert with a focus on Perception & Localization | Twitter: twitter.com/sagarcadet | Linkedin: linkedin.com/in/sagark30