🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › Linux/Bash for Web & Software Development › Lesson 7
TEC-WEB46-06 · Lesson 7 · 12 clock hours · demo

Package Management and Software Installation

Objective. Students will install, update, remove, and audit software packages using apt and dpkg on Ubuntu, and explain the role of repositories and package pinning.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

What Is a Package Manager?

On Ubuntu and other Debian-based Linux distributions, software is distributed in packages — compressed archives that contain program files, configuration templates, and metadata about dependencies. Rather than downloading and compiling source code by hand, you use a package manager to fetch, install, upgrade, and remove software in a controlled, repeatable way.

Ubuntu ships with two closely related tools:

Repositories and Sources

A repository (or repo) is a server that hosts packages signed with a cryptographic key. Ubuntu ships with official repos that cover thousands of packages. When you run `sudo apt update`, apt downloads the current package index from every configured repository so it knows what versions are available.

Third-party software — such as a current release of Node.js — is often published in a Personal Package Archive (PPA) or a vendor-maintained repo. Before adding any external repo, verify the publisher's identity and check the signing key. Adding an untrusted repo is a security risk because it could supply malicious packages with root privileges during installation.

To add the NodeSource repository and install a specific Node.js version:

```bash

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

sudo apt install -y nodejs

```

The setup script adds the repo and its signing key. Always read such scripts before running them with elevated privileges.

Core apt Commands

| Task | Command |

|---|---|

| Refresh package index | `sudo apt update` |

| Install a package | `sudo apt install package-name` |

| Upgrade all packages | `sudo apt upgrade` |

| Remove package (keep config) | `sudo apt remove package-name` |

| Remove package and config files | `sudo apt purge package-name` |

| Remove unused dependencies | `sudo apt autoremove` |

| Search for a package | `apt search keyword` |

| Show package details | `apt show package-name` |

Always run `sudo apt update` before installing or upgrading so apt works from a current index.

Installing a LAMP-Like Stack

A common web-development environment combines Apache2 (web server), PHP (server-side scripting), and a database such as MariaDB. Install all three in one command:

```bash

sudo apt update

sudo apt install -y apache2 php libapache2-mod-php mariadb-server

```

After installation, enable and start each service with systemctl:

```bash

sudo systemctl enable --now apache2

sudo systemctl enable --now mariadb

```

Verify each service is active:

```bash

sudo systemctl status apache2

sudo systemctl status mariadb

```

The output should show `active (running)`. If a service fails to start, check logs with `sudo journalctl -xe`.

Package Pinning and Holds

In production environments, an unintended upgrade can break an application that depends on a specific package version. Package pinning lets you lock a package at its current version so apt will not upgrade it automatically.

The simplest method uses `apt-mark`:

```bash

sudo apt-mark hold nodejs

```

To confirm which packages are held:

```bash

apt-mark showhold

```

To release a hold:

```bash

sudo apt-mark unhold nodejs

```

More granular control is available through `/etc/apt/preferences.d/` pin files, where you assign numeric priority values to specific versions or repositories.

Auditing with dpkg

When you need to verify what is installed, dpkg is your audit tool.

After purging MariaDB, confirm no residual config files remain:

```bash

sudo apt purge mariadb-server

sudo apt autoremove

dpkg -l | grep mariadb

```

If the status column shows `rc` (removed, config present), config files are still on disk. Re-run `sudo apt purge` to clean them. A clean removal shows no `mariadb` entries or shows `un` (unknown, not installed).

Safety and Best Practices

Never run untrusted scripts as root. Review any curl-piped installer before executing it. Use a test or staging VM before applying changes to a production server.

Back up configuration files before major upgrades. Critical files such as `/etc/apache2/apache2.conf` and `/etc/mysql/` directories should be version-controlled or snapshotted.

Principle of least privilege: install only packages your application requires. Each additional package is an additional attack surface. Remove unused packages with `sudo apt purge` and `sudo apt autoremove`.

Verify package integrity: apt checks cryptographic signatures automatically. Do not bypass these checks with flags that disable signature verification in a production system.

On shared or multi-user systems, note that `sudo apt install` gives the invoking user effective root access for that operation. Restrict sudo rights carefully and audit `/etc/sudoers` with `sudo visudo`.

Key terms9

aptAdvanced Package Tool — the high-level Debian/Ubuntu command-line package manager that resolves dependencies and communicates with repositories to install, upgrade, and remove software.
dpkgThe low-level Debian package manager that installs and tracks individual .deb packages; used directly for auditing installed files and package state.
repositoryA remote server hosting signed software packages and index files that apt queries when searching for or downloading packages.
PPA (Personal Package Archive)A third-party repository, commonly hosted on Launchpad, that provides packages not available in Ubuntu's official repos — such as newer versions of Node.js or other tools.
package pinningA mechanism that assigns priorities to packages or repositories so that apt will prefer a specific version and will not automatically upgrade beyond it.
apt-mark holdA command that locks a package at its currently installed version, preventing apt upgrade from updating it until the hold is explicitly released.
apt purgeAn apt command that removes a package and deletes its configuration files from the system, producing a cleaner removal than apt remove alone.
systemctlThe primary command-line tool for managing systemd services — used to start, stop, enable, disable, and check the status of daemons such as Apache and MariaDB.
dependencyA separate package that a target package requires in order to function; apt resolves and installs dependencies automatically when you install a package.
In class: Instructor-led walkthrough: demonstrate adding the NodeSource PPA, installing a specific Node.js version, holding the package to prevent unintended upgrades with apt-mark hold, and verifying installation with 'node -v' and 'dpkg -l'. · Guided lab: students install a LAMP-like stack (Apache2, PHP, MariaDB) using apt, enable the services with systemctl, verify each is active, then remove MariaDB cleanly with apt purge and confirm no residual config files remain. · Group discussion: instructor presents a scenario where a production server auto-updated a dependency and broke the app; students identify which apt and dpkg commands would have helped prevent or diagnose the issue.
Materials: Student VMs with internet access, Ubuntu package repositories, NodeSource installation docs, apt/dpkg man pages
Check: Instructor checks that Apache and PHP are active, the pinned Node version matches the target, and MariaDB is fully removed — all three verified to pass.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

CompTIA Linux+ — Package Management
1. A developer wants to ensure that Node.js is not automatically upgraded during a routine system update on a production Ubuntu server. Which command accomplishes this?
CompTIA Linux+ — Package Management
2. After running 'sudo apt remove mariadb-server', a sysadmin notices that 'dpkg -l | grep mariadb' still shows a status of 'rc'. What does this status indicate?
CompTIA ITF+ — Software and Application Concepts
3. Which command refreshes the local package index on an Ubuntu system so that apt knows the latest available versions from all configured repositories?
CompTIA Linux+ — System Services
4. A team installs Apache2 on Ubuntu but the service does not start at boot after the next reboot. Which command would both enable Apache2 to start at boot and start it immediately?
CompTIA Linux+ — Package Management
5. Which dpkg command lists every file that was installed onto the system by the apache2 package?
CompTIA Linux+ — Package Management
6. A production web application broke after a nightly 'apt upgrade' updated a shared library. Which combination of steps would have best prevented this outcome?
CompTIA Linux+ — Security
7. Before adding a third-party PPA to an Ubuntu server, what is the most important security step a sysadmin should take?
CompTIA ITF+ — Software and Application Concepts
8. A student installs Node.js from the NodeSource repository and wants to confirm the installed version at the command line. Which command provides this output?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.