Ubuntu Linux for Robotics · Lesson 41 of 96
Installing ROS 2 packages
apt names, finding packages, rosdep keys and building from source instead.
Estimated time · 30–45 min
Learning goals
What you will understand
- Explain installing ros 2 packages in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
Most ROS 2 packages are available as apt packages named ros-<distro>-<package-with-dashes>, for example ros-lyrical-navigation2 or ros-lyrical-turtlebot3-gazebo. Search with apt search ros-lyrical- and check with ros2 pkg list after installing. Underscores in ROS package names become dashes in apt names.
If no binary package exists, clone the source into your workspace and build it with colcon (after rosdep install). Prefer binary packages for stability; build from source only when you need a newer version or a fix. Record what you install so the robot can be reproduced.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the installing ros 2 packages commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
apt search ros-lyrical-navigation
# Find Navigation packages for your distribution.
sudo apt install ros-lyrical-navigation2 ros-lyrical-nav2-bringup
# Install Nav2 (note underscores become dashes).
ros2 pkg list | grep nav2 | head
# Confirm the packages are visible to ROS.
ros2 pkg prefix nav2_bringup
# See where the package was installed.
apt list --installed 2>/dev/null | grep ros-lyrical | wc -l
# Count installed ROS packages.
sudo apt remove ros-lyrical-navigation2
# Remove a package you no longer need.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · Build and run
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 ROS 2 packages. Expected result: /opt/ros/lyrical
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: install the package ros-lyrical-turtlesim and print its install prefix with ros2 pkg prefixExpected output
/opt/ros/lyricalStuck? Show the full solution (try it yourself first)
sudo apt install -y ros-lyrical-turtlesim
ros2 pkg prefix turtlesimExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Install turtlesim, the TurtleBot 3 Gazebo package and the Nav2 packages using apt, verify each with ros2 pkg prefix, and write down the apt name for a package with an underscore in its ROS name.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.