Skip to content

11. Package Management

11.1 APT (Debian/Ubuntu)

bash
# Update package source list
sudo apt update

# Upgrade all installed packages
sudo apt upgrade

# Update and upgrade (recommended combo)
sudo apt update && sudo apt upgrade -y

# Install software
sudo apt install nginx
sudo apt install git curl wget vim

# Uninstall software
sudo apt remove nginx          # Keep configuration
sudo apt purge nginx           # Remove configuration
sudo apt autoremove            # Clean up unnecessary dependencies

# Search for software
apt search nginx
apt show nginx

# List installed software
apt list --installed
apt list --installed | grep nginx
bash
$ sudo apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  nginx nginx-common nginx-core
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,234 kB of archives.
After this operation, 4,567 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 nginx-common all 1.18.0-6ubuntu14.4 [41.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 nginx-core amd64 1.18.0-6ubuntu14.4 [1,180 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 nginx amd64 1.18.0-6ubuntu14.4 [4.5 kB]
Fetched 1,234 kB in 2s (617 kB/s)
Selecting previously unselected package nginx-common.
(Reading database ... 185432 files and directories currently installed.)
Unpacking nginx-common (1.18.0-6ubuntu14.4) ...
Setting up nginx (1.18.0-6ubuntu14.4) ...

11.2 DNF (Fedora/CentOS/RHEL)

bash
# Install
sudo dnf install nginx

# Upgrade
sudo dnf upgrade

# Search
dnf search nginx

# Uninstall
sudo dnf remove nginx

# Clean cache
sudo dnf clean all

11.3 Pacman (Arch Linux)

bash
# Sync database and upgrade system
sudo pacman -Syu

# Install
sudo pacman -S nginx

# Search
pacman -Ss nginx

# Uninstall (along with dependencies not used by other packages)
sudo pacman -Rns nginx

11.4 Compiling from Source

Some software doesn't have pre-compiled packages and needs to be compiled from source.

bash
# Install build tools
sudo apt install build-essential

# Typical three-step compile and install process
tar -xzf software-1.0.tar.gz
cd software-1.0
./configure --prefix=/usr/local
make
sudo make install

# Install a cmake project
git clone https://github.com/example/project.git
cd project
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install

📝 Note: ⚠️ Note: Software installed from source is not managed by the package manager, making upgrades and uninstallation more difficult. Whenever possible, use the package manager to install software.