Back to Blog

How to Install Software Using APT

How to Install Software Using APT
Command of the Day
sudo apt update && sudo apt upgrade -y

What it does: Updates local package index caches and upgrades all installed system packages to their latest secure versions in a single combined command.

APT (Advanced Package Tool) is the default package management system used by Debian, Ubuntu, and their derivatives. It simplifies the installation, upgrading, configuration, and removal of software by handling dependencies automatically from trusted online repositories.

In this guide, you will master the fundamental commands of apt on your RivinCloud VPS.


1. Updating and Upgrading Packages

Before installing any new software, it is vital to synchronize your server's package index:

Step 1: Update Package Lists

sudo apt update

This downloads the newest package lists and version metadata from configured repositories. It does not install or change any existing software.

Step 2: Upgrade Installed Packages

sudo apt upgrade -y

This actually downloads and installs newer versions of all currently installed programs and libraries.

Full Distribution Upgrade

For handling major kernel updates or changed dependencies:

sudo apt dist-upgrade -y

2. Searching and Inspecting Packages

Search for Software in Repositories

apt search nginx

View Package Details and Metadata

apt show nginx

Displays description, installed version, maintainer, dependencies, and download size.


3. Installing Software

Basic Installation

sudo apt install -y nginx git curl ufw

Install a Specific Version

sudo apt install nodejs=18.19.0-1nodesource1

Reinstall a Broken Package

sudo apt install --reinstall nginx

Install a Local .deb File

sudo apt install ./package-name.deb

(APT is preferred over dpkg -i because it automatically fetches missing dependencies).


4. Removing and Cleaning Software

Remove Package (Keeps Configuration Files)

sudo apt remove nginx

Purge Package (Removes Software AND Configuration Files)

sudo apt purge nginx

Remove Stale Dependencies

When you uninstall a program, leftover dependencies that are no longer needed by any app can be safely purged:

sudo apt autoremove --purge -y

Clear Downloaded Package Archives (/var/cache/apt/archives)

Reclaim disk space by purging .deb install caches:

sudo apt clean

5. Managing PPAs and External Repositories

To install software not present in standard Ubuntu/Debian mirrors (e.g., modern PHP or Node.js versions):

Adding a PPA (Personal Package Archive)

sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

Removing a PPA

sudo add-apt-repository --remove ppa:ondrej/php

Common Mistakes

  • Running apt install without apt update first: Trying to install packages against outdated package indices leads to 404 Not Found download errors.
  • Using apt-get instead of modern apt: apt provides a cleaner user interface, progress bars, and consolidated commands compared to legacy apt-get.

Troubleshooting

  • "Could not get lock /var/lib/dpkg/lock-frontend": Another package manager instance (like unattended-upgrades) is running in the background. Wait a minute or check running processes:
    sudo lsof /var/lib/dpkg/lock-frontend
    

Best Practices

  • Periodically run sudo apt update && sudo apt upgrade -y to apply security patches.
  • Use sudo apt autoremove to prevent disk bloat from old Linux kernel versions.

Frequently Asked Questions

What is the difference between apt remove and apt purge?

apt remove deletes the program binaries but leaves your configuration files intact in /etc/. apt purge removes both the application and all related configuration files.


Conclusion

Understanding apt gives you total control over software lifecycle management on your RivinCloud VPS. Keep your server up to date and secure with regular updates!