ROS 2 installation on Ubuntu
In this guide, you will learn how to install ROS 2.
Table of Contents
Prerequisites
- Open a terminal
- Check locale settings by running
locale
command in the terminal. The output should be similar to the following: -
If the output is not
en_US.UTF-8
, you need to set the locale toen_US.UTF-8
by running the following commands: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
1. Setup Sources
Add the ROS 2 apt repository to your sources list.
sudo apt update && sudo apt install curl gnupg2 lsb-release software-properties-common
sudo add-apt-repository universe
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
2. Install ROS 2 packages
Update the package list and install the ROS 2 packages.
sudo apt update
sudo apt upgrade
sudo apt install -y ros-humble-desktop ros-dev-tools
3. Environment setup
The .bashrc
is a text file located in your home directory (also indicated as ~
). It is an hidden file, since its name starts with a dot, that is executed each time you open a new terminal. Let’s set it up to activate ROS 2 in each new terminal.
-
Open the
.bashrc
file and add the following lines at the end. Use the commandgedit ~/.bashrc
to open the file in a text editor.source /opt/ros/humble/setup.bash source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
-
To test the installation, run the following command in a new terminal:
ros2 run demo_nodes_cpp talker
You should see the following output:
[INFO] [talker]: Publishing: 'Hello World: 1' [INFO] [talker]: Publishing: 'Hello World: 2' [INFO] [talker]: Publishing: 'Hello World: 3' and so on...
-
In another terminal run the following command:
ros2 run demo_nodes_py listener
You should see the following output:
[INFO] [listener]: I heard: [Hello World: 1] [INFO] [listener]: I heard: [Hello World: 2] [INFO] [listener]: I heard: [Hello World: 3] and so on...
If you see the above output, then the installation was successful.