Package Management Basics: Installing and Updating Software in Linux
Master package management in Linux. Learn how to update repositories, install new software, and remove unused packages to keep your server secure and clean.

Previously in this course, we covered managing process lifecycles and automating routine tasks with Cron. Now that your server can run and schedule tasks, you need a way to install the tools required for your web server project.
In the world of Linux, we don't typically download .exe or .dmg files from websites. Instead, we use a package manager. Think of a package manager as a curated app store that handles the heavy lifting of downloading, verifying, and configuring software while automatically resolving "dependencies"—the other pieces of code your software needs to run.
Understanding Package Management
Package management systems operate on a simple model: they track a list of "repositories" (online storage locations for software). When you want to install something, the system checks these repositories, downloads the package, and ensures all supporting libraries are present.
While distributions vary, the two most common systems you'll encounter are:
- APT (Advanced Package Tool): Used by Debian, Ubuntu, and their derivatives.
- YUM/DNF: Used by RHEL, CentOS, Fedora, and Amazon Linux.
In this lesson, we will focus on APT, as it is the standard for most cloud-based web servers.
The Workflow: Update, Install, Remove
Effective package management follows a "refresh-install-cleanup" cycle. Because your system doesn't automatically know what new versions of software have been released since you last checked, you must manually initiate a sync.
1. Updating Package Lists
Before installing anything, you must tell your system to check the remote repositories for the latest version information. This does not upgrade your software; it only updates the index of what is available.
Bashsudo apt update
2. Installing Software
Once the list is updated, you can install a package. Let’s install htop, a useful tool for monitoring server performance, to start building out our admin toolkit.
Bashsudo apt install htop
APT will calculate the dependencies, ask for your confirmation, and then perform the installation.
3. Removing Unused Packages
Over time, your system accumulates "orphaned" dependencies—packages that were installed automatically to support an application you later deleted. Keeping these around is a security risk and a waste of disk space.
Bashsudo apt autoremove
Worked Example: Preparing the Web Server
For our ongoing project, we need to ensure our server has the necessary tools to serve web content. Let’s ensure the Nginx web server is installed and that our package index is current.
- Update the list:
sudo apt update - Install Nginx:
sudo apt install nginx - Verify installation:
nginx -v
If you ever decide to remove Nginx to replace it with another service, you would run:
Bashsudo apt remove nginx sudo apt autoremove
Hands-on Exercise
Your task is to prepare your environment by installing a classic terminal utility.
- Run
sudo apt updateto refresh your local cache. - Install the
treeutility, which helps visualize directory structures. - Run
treein your project root directory (which we provisioned in this earlier lesson). - Confirm it works and then remove it using
sudo apt remove tree.
Common Pitfalls
- Forgetting
sudo: Package management modifies system-wide files in/usr/binand/var/lib. You must usesudoto gain the necessary permissions. - Skipping
apt update: If you try to install a package without runningupdatefirst, the system might try to fetch an outdated URL that no longer exists, resulting in a "404 Not Found" error. - Mixing Package Sources: Avoid adding random external repositories (PPAs) unless you trust the source. This can lead to "dependency hell," where different versions of system libraries conflict with one another.
FAQ
Q: What is the difference between apt upgrade and apt dist-upgrade?
A: apt upgrade updates existing packages to their newest versions. apt dist-upgrade is smarter—it will intelligently handle changing dependencies and remove or add packages to resolve complex upgrade scenarios.
Q: Can I break my system with package management?
A: Yes, if you use flags like --force or install software from untrusted, non-official repositories. Always stick to the official repositories provided by your Linux distribution whenever possible.
Recap
Package management is the bedrock of system maintenance. By mastering apt update, apt install, and apt autoremove, you ensure your server remains secure, up-to-date, and free of unnecessary clutter. Just as you manage dependencies in Node.js when working with npm, you must treat system packages with similar care to ensure a stable production environment.
Up next: We will dive into Repositories and Sources to understand where these packages actually come from and how to manage your software supply chain.


