← System admin on a Raspberry Pi

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.

Your phone has an app store. What does a Pi have?

An operating system keeps programs, files and hardware apart, and apt is how you add programs. It fetches them from a software source (a repository) over the network, so lessons about it need the internet unless the programs are already on a USB stick. Offline, your teacher can set up a local source.

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

A fresh Pi

On a brand-new Pi you type sudo apt install tree straight away, without updating first. What happens?

TryTry it on the board and compare the result with your prediction.

Try: install tree

Was your prediction right?

Try it yourselfYour edits are saved in this browser.

Get the tree program onto the Pi: update the lists, then install it. Then run tree.

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: Installing, step by step

Worked exampleBefore each step, say what you think comes next.
  1. sudo apt update\text{sudo apt update}download the list of what is available. Nothing is installed yet.

Now try it yourself.

What does sudo do?

Sam wants to avoid typing sudo. Click the line where it first goes wrong.

You want to install a program but the Pi has no internet. What are your options?

ModifyChange the problem on purpose and see what happens.

Vary: change one thing

Try it yourselfYour edits are saved in this browser.

Install cowsay (remember the lists).

Use the board. This ticks when you get there.

tree is installed. Remove it.

Use the board. This ticks when you get there.

The network is down. Try sudo apt update. What happens?

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Practise

Which pair of commands installs a program on a new Pi?

Why does apt need sudo?

Review: you ssh to the Pi and run sudo apt update. Where is the list downloaded to?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Set up a new Pi

Then: on a real Pi, run sudo apt update, then apt list --upgradable to see what is waiting.

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Start by getting the list.

Another hint

sudo apt update, then sudo apt upgrade, then sudo apt install tree.

Another hint

There are 12 waiting updates; upgrade installs them.

Bring a new Pi up to date and install tree: the 12 waiting updates, and tree.

Use the board. This ticks when you get there.

Now you can
Next lesson3. Accounts, groups and sudoEach person gets an account and a private home folder. Groups give several accounts the same rights. Only users in the sudo group may use sudo, and the system logs every time they do.
For teachers

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. About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

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.

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

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.

Where it leads

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

What each step is for