ROS Installation Guide¶
Comprehensive Guide: Installing ROS 2 on Ubuntu 24.04, 22.04, and 20.04 with Colcon and Nala.¶
Optimizing ROS 2 setup using Nala for faster package management and Colcon for streamlined builds.
Introduction:¶
The Robot Operating System (ROS 2) is a critical framework for building robotic systems and applications, offering a vast suite of tools for simulation, communication, and hardware interaction. Whether you're setting up a robotics development environment on Ubuntu 24.04, 22.04, or 20.04, this guide will walk you through installing ROS 2 while leveraging advanced tools like Nala and Colcon to optimize your setup process.
For those confident with Linux systems, consider using Nala—a powerful alternative to the traditional apt package manager. Nala enables parallel downloads, improving speed and visibility, but requires some knowledge to handle any arising issues. We’ll start by setting up Nala for those familiar with Linux, followed by detailed ROS 2 installation instructions.
If you’re confident with Linux and would like to speed up the ROS 2 installation process, you can use Nala, a modern package manager that enhances apt by allowing parallel downloads and offering improved error reporting.
Why Nala and Colcon?¶
The traditional package manager apt is reliable, but can be slow due to sequential downloads and verbose error reporting. Nala provides a faster, more transparent alternative by enabling parallel downloads and simplifying package management, saving valuable time during the setup. Colcon, on the other hand, is indispensable for building ROS 2 packages, especially when working with complex dependencies across multiple packages.
1. Optional: Setting up Nala for Optimized Package Management¶
To install Nala, follow these steps:¶
Terminal command:¶
sudo apt update && sudo apt install nala
Once installed, you can replace any apt commands in this guide with nala to benefit from faster
installations. For example:
Terminal command:¶
sudo nala install ros-humble-desktop
If you’re new to package management, we recommend sticking with apt.
2. System Preparation: Configuring Locale¶
Before installing ROS 2, you must ensure your system locale is set to UTF-8. This ensures that the environment supports the correct character encoding during installation.
To configure the locale, run the following commands:¶
Check current locale settings:¶
locale
To install the local packages and configure locales :¶
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
Verify the locales settings:¶
locale
Make sure the output shows **LANG=en_US.UTF-8**. This ensures the correct locale is set
for ROS 2 installation.
3. Adding ROS 2 Sources and GPG Key¶
Next, we’ll add the ROS 2 package repository to Ubuntu and import the associated GPG key. This allows your system to recognize and install official ROS 2 packages.
Enable the Universe repository (required for ROS 2 dependencies):¶
Terminal command:¶
sudo apt install software-properties-common
sudo add-apt-repository universe
Add the ROS 2 GPG key:¶
Terminal command:¶
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 ROS 2 repository:¶
Terminal command:¶
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
Update your package list:¶
Terminal command:¶
sudo apt update
4. Installing ROS 2 Packages¶
Now that the repository is configured, you can proceed with the installation. Depending on your use case, you can choose between two installation types:
Option 1: Desktop Install (Recommended)¶
This includes the full ROS 2 desktop environment, including simulation tools, RViz, demos, and tutorials:
Terminal command:¶
sudo nala install ros-humble-desktop
For those using Ubuntu 20.04, substitute humble with foxy:
Terminal command:¶
sudo nala install ros-foxy-desktop
Option 2: ROS-Base Install (Minimal)¶
If you're running ROS 2 on resource-constrained hardware (such as a robot), you may prefer the lightweight ROS-Base install, which does not include GUI tools:
Terminal command:¶
sudo nala install ros-humble-ros-base
Once the installation is complete, proceed to set up your ROS 2 environment.
5. Installing and Configuring Colcon for Building ROS Packages¶
ROS 2 uses Colcon to build packages and manage dependencies. Let’s install Colcon along with other essential development tools:
Terminal command:¶
sudo apt install python3-colcon-common-extensions build-essential cmake python3-pip python3-vcstool
To verify that Colcon is installed correctly, check its version:¶
Terminal command:¶
colcon --version
Colcon simplifies the process of building multiple packages in your workspace and is
integral to ROS 2 development.
6. Setting Up Environment Variables¶
To enable ROS 2 commands and paths in your terminal, you must source the ROS 2 setup file in every new session.
Run the following command to source ROS 2 for the current terminal:
Terminal command:¶
source /opt/ros/humble/setup.bash
To avoid repeating this step every time you open a terminal, add this command
to your `.bashrc` file:
Terminal command:¶
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrcsource ~/.bashrc
For Ubuntu 20.04 with ROS Foxy, modify the command accordingly:¶
Terminal command:¶
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrcsource ~/.bashrc
7. Verifying Installation with ROS 2 Demos¶
To confirm that your ROS 2 installation was successful, let’s run a simple talker-listener demo.
Open a new terminal and source your ROS 2 environment:
source /opt/ros/humble/setup.bashros2 run demo_nodes_cpp talker
In another terminal, source the environment again and run the listener:
Terminal command:¶
source /opt/ros/humble/setup.bashros2 run demo_nodes_cpp listener
You should see the two nodes exchanging messages, confirming that
ROS 2 is functioning correctly.
8. Optional: Using Docker for ROS 2¶
If you prefer isolating your ROS 2 environment or need to quickly set up ROS 2 across different systems, Docker is a practical option. Docker allows you to run ROS 2 in a container without worrying about system-wide dependencies.
Install Docker:¶
Terminal command:¶
sudo apt install docker.io
Pull the ROS 2 Docker image:¶
Terminal command:¶
docker pull osrf/ros:humble-desktop
From here, you can launch ROS 2 in a containerized environment, offering
flexibility and ease of use, especially for cross-platform development.
9. Conclusion¶
By following this comprehensive guide, you’ve successfully installed ROS 2 on your Ubuntu system, optimized with tools like Nala for faster package management and Colcon for efficient building. Whether you chose the full desktop installation or the minimal base installation, you’re now ready to start developing with ROS 2.
If you encounter any issues or need further customization, refer to the official ROS 2 documentation or seek support from the ROS community forums. Happy coding with ROS 2!