ROS 2 Lyrical Luth · Lesson 26 of 86
Installing Gazebo Harmonic
Gazebo Sim, ros_gz packages, checking the version pairing and running the first world.
Estimated time · 45–60 min
Learning goals
What you will understand
- Explain installing gazebo harmonic in your own words
- Use it in a small robotics example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
Gazebo is the physics simulator used with ROS 2. Modern Gazebo (formerly Ignition) is installed as gz-sim and connects to ROS 2 through the ros_gz packages. Each ROS 2 distribution supports specific Gazebo versions: check the ros_gz table for the pairing before installing (this course uses Gazebo Harmonic).
After installing, start it with gz sim and a world file. gz topic and gz service are the simulator's own tools, similar to the ros2 CLI. Software rendering can be slow; a GPU or a reduced scene helps.
Guided lesson
Work through these steps
- 1.
Source the ROS 2 Lyrical environment in a fresh terminal.
- 2.
Read the installing gazebo harmonic example and identify what each line does.
- 3.
Build only the affected package, source the workspace overlay, and run the example.
- 4.
Inspect the result from a second terminal with the ros2 CLI or RViz2 and compare it with the expected result.
Worked example
Read it before you run it
sudo apt update
# Refresh the package index.
sudo apt install ros-lyrical-ros-gz
# Install Gazebo and the ROS 2 bridge packages for this distribution.
gz sim --version
# Confirm the Gazebo version.
gz sim -v 3 shapes.sdf
# Open the built-in shapes world with verbose logging.
gz topic -l
# List Gazebo's own topics.
ros2 pkg list | grep ros_gz
# Confirm the ROS 2 bridge packages are visible.What the example is doing
- 1.The ros2 commands query the running graph; they do not prove that a node's internal behavior is correct.
- 2.Build from the workspace root, then source install/setup.bash so the shell can discover the new package.
- 3.Use a second sourced terminal to inspect nodes and interfaces while the example runs.
Watch it run · Mobile robot
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Installing Gazebo Harmonic. Expected result: The Gazebo window opens with shapes
Practice code
Now type it yourself
Copy the starter into your ROS 2 package, replace every TODO, then build with colcon build and run it from a sourced terminal.
source /opt/ros/lyrical/setup.bash
# TODO: open the built-in world shapes.sdf with gz sim and verbosity 3Expected output
The Gazebo window opens with shapesStuck? Show the full solution (try it yourself first)
source /opt/ros/lyrical/setup.bash
gz sim -v 3 shapes.sdfExpected result
How you know it worked
- ROS_DISTRO is lyrical in every terminal used for the exercise.
- The complete package from the exercise builds and the expected graph entity appears in a second terminal.
Practical exercise
Apply the lesson
Install ros_gz, start shapes.sdf, press Play, list gz topics, and record the Gazebo version and the pairing table entry for your ROS 2 distribution.
Before you continue
- ROS_DISTRO reports lyrical in every terminal you used
- The example builds and runs without errors
- You checked the result with a ros2 command, RViz2 or a test, not just by reading the code
If something goes wrong
Source /opt/ros/lyrical/setup.bash, build from the workspace root, then source install/setup.bash in that terminal.
Confirm both terminals use Lyrical, the same ROS_DOMAIN_ID, and compatible network/discovery settings.