Read a sample: 1. Build a Safe Package-Management Lab
The best place to learn package management is a system you can afford to break. Installing a utility may look like a small change, but the package manager can also install dependencies, replace files, update shared libraries, or start services. Later exercises will ask you to examine those decisions and recover from problems. A disposable lab gives you room to do that without experimenting on a work laptop or production server.
This chapter builds a foundation for the rest of the book: one Debian-based virtual machine and one Red Hat-based virtual machine, administrative access on each, a record of their initial state, and a checkpoint you can use for recovery. You do not need to master virtualization first. You do need to know which computer is receiving each command and how to return the lab to a known state.
The examples in this book use two package-management families:
- Debian-based systems, such as Debian and Ubuntu, commonly use APT for repository-aware package management and dpkg for lower-level package operations.
- Red Hat-based systems, such as Fedora and supported releases of distributions in the Red Hat Enterprise Linux family, commonly use DNF for repository-aware management and RPM for lower-level operations.
For a straightforward lab, use a current, supported Debian or Ubuntu release for the first virtual machine and a current, supported Fedora release or another suitable Red Hat-family distribution for the second. Download installation media from the distribution’s official site. Follow its published instructions for verifying the download where available; an unexpected download should not be the foundation of a security-conscious lab.
Commands, package names, default repositories, and output vary between releases. DNF itself may differ by version, and a distribution can customize a tool’s behavior. The book’s commands illustrate common workflows, not a promise that every line of output will match your screen. When an option is unavailable or a package name differs, consult the installed tool’s help and the documentation for your distribution and release.
You may use an existing hypervisor on your computer or a reputable hosted virtualization service. The interface will differ, but the decisions are similar: create a virtual disk, attach installation media, install the operating system, and provide enough resources for it to run comfortably. Two virtual CPUs, 2–4 GB of memory, and a virtual disk of at least 20 GB are reasonable starting points for a small command-line lab, subject to the distribution’s requirements and your host’s capacity. You can run the machines one at a time if resources are limited.
Use separate virtual machines rather than trying to combine both package families in one installation. Name them something unmistakable, such as debian-lab and redhat-lab. These names are labels for your practice environment; they do not have to match a particular distribution.
Create the first virtual machine in your hypervisor and attach the Debian-family installation image. Choose a normal installation onto the virtual disk, not a physical disk containing data you need. During installation, create a regular user account with a password you can remember. Enable administrative access for that account as described in the next section.
Repeat the process with the Red Hat-family image. A minimal or server-oriented installation is sufficient for the exercises, provided you have a shell, networking, and the package-management tools supplied by the distribution. A graphical desktop is optional.
Keep the lab isolated from systems you do not intend to change. A network mode that allows outbound access through the host, often called NAT, is a useful default for downloading packages. It is not a substitute for checking your hypervisor’s network settings: avoid exposing lab services to other networks unnecessarily, and do not configure bridged networking simply because an example elsewhere uses it.
Before continuing, confirm that you can open a console for each machine, sign in as your regular user, and shut it down and start it again. The hypervisor’s console is especially useful if a later network or SSH configuration problem prevents remote access.
Package database changes generally require administrative privileges. Routine observation does not. Working as a regular user and elevating only the commands that need it makes the boundary visible and reduces the chance that an ordinary typing mistake changes the system.
On each machine, check whether sudo is available:
bash
command -v sudo
If the command prints a path, test your account’s authorization:
bash
sudo -v
You may be asked for your user password. A successful command ordinarily returns without additional output. If sudo is missing or your account is not authorized, follow the installation or administration documentation for that distribution to grant your lab user appropriate access. Some installations configure sudo during setup; others require an administrator to install or configure it. Do not repeatedly guess passwords or change privilege settings you do not understand.
Where the installation provides a root account, you may be able to use su - and the root password to perform initial configuration. Return to the regular account afterward. The examples in this book use sudo for commands that require elevation; omit it only when you are deliberately working in an already privileged shell.
Check which account and machine you are using:
bash
whoami
hostname
Make a habit of running these commands when switching between terminals. They provide a simple check, but they are not proof that you are on the intended virtual machine if names are duplicated. Use your hypervisor’s console or window labels as an additional…