November 21, 2024

Install ROS 2 Iron Irwini on the Ubuntu Linux Operating Systems BY BUILDING FROM SOURCE

In this Robot Operating System (ROS) tutorial, we explain how to install the ROS 2 Iron Irwini version on Ubuntu Linux operating systems by building from source. This installation method is for advanced ROS2 users and developers who need to change and customize the ROS 2 base and ROS 2 installation. We have also created a tutorial webpage for installing ROS 2 by using binary packages. The tutorial is given here. The installation of ROS 2 from binary packages is much quicker and is recommended for people who want to quickly start with ROS 2 programming and for absolute beginners.

The YouTube tutorial accompanying this webpage is given below.

In the sequel, we explain the necessary steps that need to be performed in order to install ROS 2 Iron Irwini.

STEP 1: Verify that the Correct Linux Version is Installed on the System

To be able to install and run ROS 2 Iron Irwini, we need to have a computer with the Ubuntu Linux operating system. Furthermore, the Ubuntu Linux version should be Jammy – 22.04. The first step is to open a Linux terminal and to verify the Linux installation by typing

lsb_release -a

If you have Ubuntu 22.04 running on your system, you should obtain an output similar to this one

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.3 LTS
Release:	22.04
Codename:	jammy

If for example, you have Ubuntu version 20.04, then you need to install version 22.04, otherwise, you will not be able to install and run ROS2 Iron Irvini. Similarly, you will not be able to install ROS1 Noetic distribution on Ubuntu 22.04.

STEP 2: System Setup

First, we need to make sure that our Linux environment supports UTF-8. UTF-8 is a standard for variable-length character encoding that is originally used for electronic communication. Open a terminal window and type

locale  

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

Next, we need to set the required repositories. First, we have to make sure that the Ubuntu Universe repository is enabled. To do that, click on “Show Applications”, then search for “Software and Updates”. Then, click on the “Ubuntu Software” menu, and enable “Community-maintained free and open-source software (universe)”. The figure shows below shows the “Ubuntu Software” menu:

Then, in the terminal execute these commands

sudo apt install software-properties-common

sudo add-apt-repository universe

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

Next, we need to install development tools

sudo apt update && sudo apt install -y \
  python3-flake8-docstrings \
  python3-pip \
  python3-pytest-cov \
  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 \
  ros-dev-tools

Step 3: Build ROS 2

First, we need to get ROS 2 code files. We create a workspace and clone all the repositories:

mkdir -p ~/ros2_iron/src

cd ~/ros2_iron

vcs import --input https://raw.githubusercontent.com/ros2/ros2/iron/ros2.repos src

Next, we need to install dependencies using rosdep:

sudo apt upgrade

sudo rosdep init

rosdep update

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

Next, we build the code in the workspace and setup the environment. If we have already installed ROS 2, we have to make sure that the new version of ROS2 is installed in a new environment that does not have another version sourced. That is, we have to make sure that ROS 2 is not sourced in the .bashrc file. To verify that, type

printenv | grep -i ROS

We should only see the current version we are installing:

aleksandar@alex:~/ros2_iron$

Then, type

cd ~/ros2_iron/

colcon build –symlink-install

On our machine, this step will take more than 15 minutes. If there are some issues or errors during the build process, we can use 

--packages-skip

colcon flag to ignore the packages that are causing errors. For example, if there are issues or if we do not want to install the OpenCV library, we can skip building the packages that depend on OpenCV by typing

colcon build --symlink-install --packages-skip image_tools intra_process_demo

Next, we setup the environment by sourcing the file “local_setup.bash”

. ~/ros2_iron/install/local_setup.bash

STEP 4: Verify the installation by running the Hello World Example

Let us run a talker-listener example in order to verify the installation. First, open a new terminal, and run the talker by typing

. ~/ros2_iron/install/local_setup.bash

ros2 run demo_nodes_cpp talker

This will source the setup file and run the talker. Then, open another terminal and run the listener

. ~/ros2_iron/install/local_setup.bash

ros2 run demo_nodes_py listener

This will source the setup file and run the listener.