Vucense

Linux Package Management 2026: apt, dpkg & snap on Ubuntu 24.04

🟢Beginner

Complete Linux package management on Ubuntu 24.04: apt install/remove/upgrade, dpkg commands, PPA management, unattended-upgrades, snap vs apt trade-offs, and repository management.

Linux Package Management 2026: apt, dpkg & snap on Ubuntu 24.04
Article Roadmap

Key Takeaways

  • update before install: apt-get update syncs the local package index — without it you may install an outdated version. Run it before every install session.
  • upgrade vs dist-upgrade: upgrade updates installed packages but won’t add or remove packages. dist-upgrade (or full-upgrade) can add/remove packages to satisfy dependencies — safer on servers.
  • apt vs apt-get: apt is the human-friendly CLI; apt-get is the scripting-safe version with consistent output format. Use apt-get in scripts, apt in terminals.
  • Unattended security updates: Enable unattended-upgrades for automatic security patching — the single most impactful low-effort security improvement for production servers.

Introduction

Direct Answer: How do I manage packages on Ubuntu 24.04 with apt in 2026?

The core apt commands: sudo apt-get update (sync package lists), sudo apt-get install nginx (install), sudo apt-get remove nginx (remove, keep config), sudo apt-get purge nginx (remove + config), sudo apt-get upgrade (upgrade all), sudo apt-get autoremove (remove unneeded dependencies), and apt-cache search keyword (search packages). For a specific package: apt-cache show nginx (view details), apt-cache policy nginx (see available versions and which repo). To install from a .deb file: sudo dpkg -i package.deb && sudo apt-get install -f (the -f fixes any unmet dependencies). Enable automatic security updates with sudo apt-get install unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades.


Part 1: Core apt Commands

Package management on Ubuntu is one of the most frequently executed operational workflows. These commands let you synchronize repository metadata, install and remove software safely, and inspect package versions before making changes.

# ── Update & Upgrade ──────────────────────────────────────────────────────
sudo apt-get update                  # Sync package index from repositories
sudo apt-get upgrade -y              # Upgrade all installed packages (safe)
sudo apt-get dist-upgrade -y         # Upgrade with dependency changes (more thorough)
sudo apt-get full-upgrade -y         # Same as dist-upgrade (modern alias)

# ── Install & Remove ──────────────────────────────────────────────────────
sudo apt-get install -y nginx        # Install (auto-confirm with -y)
sudo apt-get install -y nginx=1.27.3 # Install specific version
sudo apt-get remove nginx            # Remove (keep config files)
sudo apt-get purge nginx             # Remove + delete config files
sudo apt-get autoremove              # Remove unused dependency packages

# ── Search & Info ─────────────────────────────────────────────────────────
apt-cache search "web server"        # Search by keyword
apt-cache show nginx                 # Package details (version, size, deps)
apt-cache policy nginx               # Which version is installed vs available
apt list --installed | grep nginx    # Check if installed
apt list --upgradable                # List packages with available updates

Expected output of apt-cache policy nginx:

nginx:
  Installed: 1.27.3-1~noble1
  Candidate: 1.27.3-1~noble1
  Version table:
 *** 1.27.3-1~noble1 500
        500 http://nginx.org/packages/ubuntu noble/nginx amd64 Packages

Part 2: dpkg — Low-Level Package Management

dpkg is the lower-level package tool under apt. Use it when you need to inspect installed package files, query ownership of a path, install local .deb artifacts, or repair broken package state.

# List installed packages
dpkg -l                              # All installed packages
dpkg -l | grep nginx                 # Filter by name
dpkg -l | awk '/^ii/{print $2}' | wc -l  # Count installed packages

# Package file information
dpkg -L nginx                        # List all files installed by nginx
dpkg -S /etc/nginx/nginx.conf        # Which package owns this file?
dpkg --info package.deb              # Info about a local .deb file

# Install a .deb file
sudo dpkg -i package.deb
sudo apt-get install -f              # Fix any broken dependencies

# Configure unconfigured packages
sudo dpkg --configure -a

Expected output of dpkg -S /etc/nginx/nginx.conf:

nginx-common: /etc/nginx/nginx.conf

Part 3: Adding Repositories (PPAs)

When the Ubuntu archive is too old for a package you need, adding a verified repository or PPA is the correct approach. This section shows how to configure a secure third-party repo and pin packages to avoid unintended upgrades.

# Add official Nginx repository (newer than Ubuntu's default)
sudo apt-get install -y curl gnupg

curl https://nginx.org/keys/nginx_signing.key | \
    sudo gpg --dearmor -o /usr/share/keyrings/nginx.gpg

echo "deb [signed-by=/usr/share/keyrings/nginx.gpg] http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | \
    sudo tee /etc/apt/sources.list.d/nginx.list

sudo apt-get update
sudo apt-get install -y nginx

# Pin nginx to stay on official repo (prevent auto-downgrade to Ubuntu's older version)
cat | sudo tee /etc/apt/preferences.d/nginx << 'EOF'
Package: nginx
Pin: origin nginx.org
Pin-Priority: 1001
EOF

Part 4: Unattended Security Upgrades

Automatic security patching reduces risk and operational overhead on production servers. These commands install and enable unattended upgrades so critical CVE fixes apply automatically overnight.

sudo apt-get install -y unattended-upgrades update-notifier-common

# Enable unattended upgrades (security patches only by default)
sudo dpkg-reconfigure -plow unattended-upgrades

# Verify configuration
cat /etc/apt/apt.conf.d/50unattended-upgrades | grep -A2 "Unattended-Upgrade::Allowed"

# Check unattended-upgrades status
sudo systemctl status unattended-upgrades --no-pager | grep "Active:"
sudo cat /var/log/unattended-upgrades/unattended-upgrades.log | tail -5

Expected output:

     Active: active (running)
2026-04-29 04:10:01,234 INFO Packages that were upgraded: libssl3 libc6 openssl

Security patches applied automatically overnight.


Part 5: snap vs apt

apt and snap each have valid use cases, but on Ubuntu server deployments apt is usually the better choice. This section compares the trade-offs so you can choose the right packaging tool for performance and maintainability.

# snap: containerised apps (large, slower start, good for desktops)
snap info code                # Check if available as snap
sudo snap install code        # VS Code (desktop app — good snap use case)
snap list                     # List installed snaps

# For servers: avoid snap, use apt equivalents
sudo snap install node        # ✗ Don't do this on servers
sudo apt-get install nodejs   # ✓ Use apt on servers

# Compare sizes
dpkg -l nginx | awk 'NR==3{print $2}'
du -sh /snap/*/current 2>/dev/null | sort -h | tail -5

Verdict: Use snap for GUI apps and tools without apt equivalents. For server packages (nginx, postgresql, nodejs, python3), always prefer apt — faster start, smaller footprint, no confinement issues.


Conclusion

Ubuntu 24.04 package management centres on three tools: apt-get for interactive and scripted installs, dpkg for inspecting installed packages and handling .deb files, and unattended-upgrades for automatic security patching. Enable unattended-upgrades on every production server — it’s the highest-impact, lowest-effort security automation available.

See Ubuntu 24.04 LTS Server Setup Checklist for unattended-upgrades in the context of full server hardening.


People Also Ask

This short FAQ answers the package management questions most frequently encountered on Ubuntu 24.04.

What is the difference between apt and apt-get?

apt is the newer, human-friendly interface with coloured output and progress bars. apt-get is the older, scripting-safe interface with stable, parseable output. Both install packages from the same repositories. The practical rule: use apt when typing commands interactively in a terminal; use apt-get in shell scripts and automation (Dockerfiles, CI scripts) where consistent output format matters.

How do I find which package provides a specific command?

Use apt-file search after installing apt-file: sudo apt-get install apt-file && sudo apt-file update && apt-file search /usr/bin/nginx. Or use dpkg -S $(which nginx) to find which installed package owns a currently-installed file. For files not yet installed: apt-cache search keyword to find relevant packages.


Further Reading

External Resources

Tested on: Ubuntu 24.04 LTS. apt 2.7.14. Last verified: April 29, 2026.

Divya Prakash

About the Author

AI Systems Architect & Founder

Graduate in Computer Science | 12+ Years in Software Architecture | Full-Stack Development Lead | AI Infrastructure Specialist

Divya Prakash is the founder and principal architect at Vucense, leading the vision for sovereign, local-first AI infrastructure. With 12+ years designing complex distributed systems, full-stack development, and AI/ML architecture, Divya specializes in building agentic AI systems that maintain user control and privacy. Her expertise spans language model deployment, multi-agent orchestration, inference optimization, and designing AI systems that operate without cloud dependencies. Divya has architected systems serving millions of requests and leads technical strategy around building sustainable, sovereign AI infrastructure. At Vucense, Divya writes in-depth technical analysis of AI trends, agentic systems, and infrastructure patterns that enable developers to build smarter, more independent AI applications.

View Profile

Further Reading

All Dev Corner

Comments