← Teacher guide

Install software with apt

On a Pi you add programs with apt, from a software source on the internet. You update the lists first, then install. sudo runs one command as the administrator, and the system records who used it.

System admin on a Raspberry Pi · Set up · about 40 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min

Before class

Try the boards yourself.

The one idea: the operating system keeps programs apart from users, so changing the system needs an administrator, and apt fetches programs from a software source.

Simplification: the pretend software source has seven packages (samba, jellyfin, ufw, tree, cowsay, unattended-upgrades and vim); real ones have tens of thousands. Pi OS Lite already has nano, openssh-server and cron.

Offline: the course works without the internet on the pretend Pi. On a real Pi with no internet, plan for it in advance: download the .deb packages and their dependencies on another computer and install with sudo apt install ./file.deb; or run a local mirror (for example apt-cacher-ng on one Pi in the room); or use the Pi's own power: with no network, sudo apt update fails by design. Jellyfin is not in Raspberry Pi OS's own list: a real install adds Jellyfin's repository first (lesson 6 says so). Say this before students try it for real.

With internet: automatic security updates (unattended-upgrades) belong in the last lessons.

Real Pi (optional, any time): the pretend Pi is the same for every student, so nothing here needs hardware. If you have Pis, any number per group works, Pi 4 or Pi 5. A Pi 5 needs a 27 W USB-C supply (a 15 W phone charger makes it complain and limit USB power). Students can sit at a Pi with a screen and keyboard, or reach it by ssh from a laptop once it is on the network. Either start works for every lesson after the first: choose a ready-made image (you set the hostname, the user and ssh once, then clone the card) or have students flash their own with Raspberry Pi Imager (OS: Raspberry Pi OS Lite 64-bit; in the settings set a hostname, a user and password, ssh on, and Wi-Fi if needed). Both reach lesson 2 in the same state. To start again: reflash the card, or write a short reset script (remove added users, sudo apt remove, restore saved config files) and run it.

Running the lesson

  1. Predict: wrong answers think apt already knows everything.
  2. Try: ask what update changed.
  3. Worked example: stop at the sudo question and ask who decides who may sudo (lesson 3).
  4. Vary: after the offline task, ask what a school would do.
  5. Make: ask why admins update first on a new machine.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Update versus upgrade. Update gets the list; upgrade installs newer versions. Say it as: update the menu, upgrade the meal.

When students get stuck

What you will seeA question to askThe fix
A student gets 'Unable to locate package'.Did you run sudo apt update?Update the lists, then install.
A student gets 'Permission denied'.Did you use sudo?sudo apt install name.

Answers to the checks

  1. a fresh Pi: On a brand-new Pi you type sudo apt install tree straight away, without updating first. What happens?
    Error: Unable to locate package tree. apt only knows the packages on its list, and a new Pi has not downloaded the list yet. sudo apt update fetches it.
  2. Try: install tree: Get the tree program onto the Pi: update the lists, then install it. Then run tree.

    sudo apt update, then sudo apt install tree. sudo is needed because changing the system is for administrators.
  3. Installing, step by step: What does sudo do?
    Runs one command as the administrator, if you are allowed
    sudo is a pass for one command. Only users in the sudo group may use it, and it records who did what.
  4. Find the mistake: Sam wants to avoid typing sudo. Click the line where it first goes wrong.
    line 2
    Line 2: as root, every typo can delete or break anything, and the log shows only 'root'. sudo asks for one command at a time and records who ran it.
  5. No internet: You want to install a program but the Pi has no internet. What are your options?
    A local software source, or packages on a USB
    apt reads from a software source. Your school can host one, or you can carry packages in on a USB stick. Without a source, apt can't update.
  6. Another program: Install cowsay (remember the lists).

    sudo apt update, then sudo apt install cowsay.
  7. Take one away: tree is installed. Remove it.

    sudo apt remove tree.
  8. No network: The network is down. Try sudo apt update. What happens?

    apt can't reach the source, so it can't fetch the list. Without network, use a local source or a USB stick.
  9. Order: Which pair of commands installs a program on a new Pi?
    sudo apt update, then sudo apt install name
    update gets the list, then install uses it.
  10. Why sudo: Why does apt need sudo?
    Installing changes the whole system
    Only administrators may change the whole system; a normal user can't. That is why permission matters.
  11. Review: ssh: Review: you ssh to the Pi and run sudo apt update. Where is the list downloaded to?
    The Pi
    After ssh, commands run on the Pi.
  12. set up a new Pi: Bring a new Pi up to date and install tree: the 12 waiting updates, and tree.

    Update the lists, upgrade the 12 waiting packages, install tree. Admins do this before anything else on a new machine.

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: change one thing › Another program

Open task: any program that does what the step asks.

Vary: change one thing › Take one away

Open task: any program that does what the step asks.

Vary: change one thing › No network

Open task: any program that does what the step asks.

set up a new Pi

Open task: any program that does what the step asks.

Stretch and support

Stretch: Find out what a repository is and why Jellyfin asks you to add one.

Support: A card with the order: update, then install.

Exit ticket

Why do you run sudo apt update before installing?

It downloads the list of packages; without it, a new Pi does not know what exists.

What each step is for

Where it leads

Links: The command line (permissions); next: Accounts, groups and sudo (who is allowed to sudo).