In this brief ROS2 tutorial, we explain how to verify if ROS2 is installed and how to verify the ROS2 version. Finally, we explain how to test if ROS2 is working properly. This video tutorial is developed under the assumption that you are using ROS2 Jazzy. However, everything explained in this tutorial applies to any other ROS2 version. The YouTube tutorial is given below.
How to Check if ROS2 is Installed and How to Check ROS2 Version
If any version of ROS2 is installed, it should be located in the folder /opt/ros . Consequently, you can navigate to that folder and check if there is a folder called humble, iron, or jazzy
cd /opt/ros
ls -la
In my case, the response looks like this:
total 12
drwxr-xr-x 3 root root 4096 Feb 18 12:21 .
drwxr-xr-x 7 root root 4096 Feb 18 12:21 ..
drwxr-xr-x 9 root root 4096 Feb 18 12:21 jazzy
The name of the folder is jazzy, which means that most likely ROS2 Jazzy Jalisco is installed. However, we have to verify that this folder is not empty
ls -la /opt/ros/jazzy
And you should see something like this
total 124
drwxr-xr-x 9 root root 4096 Feb 18 12:21 .
drwxr-xr-x 3 root root 4096 Feb 18 12:21 ..
drwxr-xr-x 2 root root 4096 Feb 18 12:21 bin
drwxr-xr-x 112 root root 4096 Feb 18 12:21 include
drwxr-xr-x 82 root root 36864 Feb 18 12:21 lib
-rw-r--r-- 1 root root 373 Apr 18 2024 local_setup.bash
-rw-r--r-- 1 root root 3901 Dec 18 02:58 local_setup.sh
-rw-r--r-- 1 root root 15895 Apr 18 2024 _local_setup_util.py
-rw-r--r-- 1 root root 379 Apr 18 2024 local_setup.zsh
drwxr-xr-x 6 root root 4096 Feb 18 12:21 opt
-rw-r--r-- 1 root root 349 Apr 18 2024 setup.bash
-rw-r--r-- 1 root root 4274 Dec 18 02:58 setup.sh
-rw-r--r-- 1 root root 622 Apr 18 2024 setup.zsh
drwxr-xr-x 295 root root 12288 Feb 18 12:21 share
drwxr-xr-x 4 root root 4096 Feb 18 12:21 src
drwxr-xr-x 3 root root 4096 Feb 18 12:21 tools
However, we still have to verify that ROS2 is working properly. First of all, you need to source the ROS2 environment. To do that, you need to type this:
source /opt/ros/jazzy/setup.bash
If in your case, the ROS2 version is Humble, you need to type this
source /opt/ros/humble/setup.bash
Next, let us see if our system is able to recognize the ROS2 environment:
printenv ROS_DISTRO
The output should be jazzy or humble, depending on the ROS2 distribution that is installed. You can also type this
echo $ROS_DISTRO
and this command should produce the same output as “printenv ROS_DISTRO”.
Remember that these commands have to be executed after executing the source command. If you execute them before sourcing the environment these commands will not produce any output.
How to Verify If ROS2 is Working Properly
Finally, let us, verify that ROS2 is installed by running the Talker-listener ROS2 example. Namely, every ROS2 distribution comes with simple examples that are used to verify the ROS2 installation. One of these examples is the Talker-listener example. Namely, in one terminal we will start a Talker node which will send messages with increasing strings, and in another terminal we will start a Listener example that will run a node that should receive these messages and print them on the computer screen.
To start the talker node, open a terminal and type this
source /opt/ros/jazzy/setup.bash
ros2 run demo_nodes_cpp talker
The output should look like this
[INFO] [1739899403.277735313] [talker]: Publishing: 'Hello World: 15'
[INFO] [1739899404.277803622] [talker]: Publishing: 'Hello World: 16'
[INFO] [1739899405.278057126] [talker]: Publishing: 'Hello World: 17'
Here, messages with an increasing number are displayed on the screen and communicated over an appropriate topic. To see the messages on the Listener side, open a new terminal and type this:
source /opt/ros/jazzy/setup.bash
ros2 run demo_nodes_py listener
The output should look like this
[INFO] [1739899403.287051260] [listener]: I heard: [Hello World: 15]
[INFO] [1739899404.280117036] [listener]: I heard: [Hello World: 16]
[INFO] [1739899405.280105425] [listener]: I heard: [Hello World: 17]
If you are able to run this example, this means that ROS2 is working properly on your computer.