CodeTheRobot

Ubuntu Linux for Robotics · Lesson 06 of 96

Package management with APT

sudo apt update, apt install, apt remove, searching and reading package information.

Estimated time · 45–60 min

Learning goals

What you will understand

  • Explain package management with apt 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

APT installs software from signed repositories and tracks dependencies. sudo apt update refreshes the list of available packages (it does not install anything). sudo apt install <package> installs one, sudo apt upgrade updates installed packages, and sudo apt remove removes one.

Before installing, look at the package: apt search finds names, apt show describes one and apt policy shows which version and repository it comes from. Install only from repositories you trust, and never mix instructions written for a different Ubuntu release.

Guided lesson

Work through these steps

  1. 1.

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

  2. 2.

    Read the package management with apt 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

sudo apt update
# Refresh the package lists from the repositories.
apt search htop
# Search for packages related to htop.
apt show htop
# Read what it is, its version and its dependencies.
sudo apt install htop
# Install it (sudo is needed because it changes the whole system).
apt list --installed | grep htop
# Confirm it is installed.
sudo apt remove htop
# Remove it again.
sudo apt autoremove
# Remove dependencies that nothing needs any more.

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 Package management with APT. Expected result: Package: bash

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: show only the first line of information for the package bash (apt show, then grep -m1 '^Package:')

Expected output

Package: bash
Stuck? Show the full solution (try it yourself first)
apt show bash 2>/dev/null | grep -m1 '^Package:'

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

Install tree and htop, run both, remove them, and write which commands changed the system and which only read information.

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.