Building ROS2 Humble in Debian 12 Bookworm or any other distro

Building ROS2 Humble in Debian 12 Bookworm or any other distro

Humble is the new LTS release with an end of life of 2027 so that is why I am choosing this but if you want to install any other distribution it is almost the same.

ROS2 is not available as a binary package in debian unlike ubuntu. So we need to build everything from source. Lets take notes from the official install guide itself, and later we will learn how to add new packages to the base environment.

Following the official guide:

The official guide offers us how we can build ROS2 in a workspace. Then, What is a workspace? A workspace is where all of your source files are and which can be built into binary files.

Now a workspace has source files but how do you get those? And ROS is built around multi-packages which means there are many repository that make up a ROS distribution.
Now a single package can have multiple versions. A distribution takes a specific version of the package. Since there are a lot of packages that we need to track to install ROS. Luckily this problem is already solved with ROS maintaining the list of packages and their versions required to make a ROS distribution. The repo where ROS maintains this is ros2/ros2.

By default is in branch rolling, we want to install humble so lets change the branch to humble.

The multiple packages sources that we talked about are provided in the ros2.repos file.

Creating a workspace:

A ROS workspace should look like this.

A keen eye among you should notice that there is already ros2.repos file from the github repository.
src: is where all of your source file live
build,install and log: these are created by the build system, we will get into these later.

Create a similar directory structure. ros_ws is the main workspace directory and it contains all of those subdirectory listed above. You can name the workspace to your liking but since we are building ros itself in the workspace I like to name it humble_ws since we are installing the humble distribution.

To get the ros2.repos file run, make sure to tweak the folder name as required.

mkdir -p ~/humble_ws/src
cd ~/humble_ws
wget https://github.com/ros2/ros2/raw/humble/ros2.repos 

Installing dependencies:

Lets install the base dependencies that are required for ROS environment.

Install the keys to add a debian source.

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

Add the ROS2 debian source for bookworm.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu bookworm main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
Install the development packages:
sudo apt update && sudo apt install -y \
  python3-flake8-docstrings \
  python3-pip \
  python3-pytest-cov \
  ros-dev-tools
sudo apt install -y \
   python3-flake8-blind-except \
   python3-flake8-builtins \
   python3-flake8-class-newline \
   python3-flake8-comprehensions \
   python3-flake8-deprecated \
   python3-flake8-import-order \
   python3-flake8-quotes \
   python3-pytest-repeat \
   python3-pytest-rerunfailures
Getting all the sources:

We will be using vcstool to get all the repositories listed in ros2.repos file.

cd ~/humble_ws
vcs import src < ros2.repos
Installing the dependencies required for sources:

Any source is built with some dependency. Those dependency need to be installed in our machine so that we can build the sources.

ROS has a tool called rosdep that is able to do all of this for us.
Lets initialize rosdep.

sudo rosdep init
rosdep update

Now getting all the required dependencies with rosdep.

cd ~/humble_ws
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

Building ROS2:

Now we have all the sources and their dependencies installed. The next step is to build all of those source files.

cd ~/humble_ws/
colcon build --symlink-install

After building the files you can use your ROS workspace by sourcing the setup file.

. ~/humble_ws/install/setup.bash

Testing the install:

Run this is one terminal.

. ~/humble_ws/install/setup.bash
ros2 run demo_nodes_cpp talker

Listen for the reply in another terminal.

. ~/humble_ws/install/setup.bash
ros2 run demo_nodes_py listener
Output:

The output should something like this:

Hooray!! you have successfully installed ROS.

Note:

I have taken reference from the official install and would like to thank all the maintainers for their effort in keeping the documentation up to date.

Refer the documentation to learn more about ROS.