CodeTheRobot

Ubuntu Linux for Robotics · Lesson 33 of 96

Add the ROS 2 apt repository

Locale, universe, the ros2-apt-source package and the signing key.

Estimated time · 30–45 min

Learning goals

What you will understand

  • Explain add the ros 2 apt repository 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

ROS 2 packages come from the ROS project's own apt repository. Before adding it, make sure Ubuntu uses a UTF-8 locale and that the universe repository is enabled. The ros2-apt-source package installs the repository definition and its signing key for your Ubuntu codename, so apt can verify every package.

Follow the installation page of your ROS 2 distribution for the exact commands: repository setup changes between releases. Do not copy commands for a different distribution or Ubuntu version.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the add the ros 2 apt repository commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

locale
# Check that the language settings show UTF-8.
sudo apt install software-properties-common curl
# Install the tools needed to add repositories.
sudo add-apt-repository universe
# Enable Ubuntu's universe repository.
sudo apt update && sudo apt install curl -y
# Refresh and make sure curl is available.
# Install the ros2-apt-source .deb package for your Ubuntu codename (see the ROS 2 installation page)
# This adds the repository and its key.
sudo apt update
# Refresh so the ROS 2 packages are visible.
apt-cache policy ros-lyrical-desktop
# Confirm the package is now available from the ROS repository.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 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.

sourcecompilerprogramBUILD AND RUN

Demo for Add the ROS 2 apt repository. Expected result: Candidate: a version from packages.ros.org

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.

sudo apt update
# TODO: check where apt would install ros-lyrical-desktop from

Expected output

Candidate: a version from packages.ros.org
Stuck? Show the full solution (try it yourself first)
sudo apt update
apt-cache policy ros-lyrical-desktop

Expected 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

Set up the repository on a fresh Ubuntu installation, then run apt-cache policy for a ROS package and record which repository and version apt would install.

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

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.