Lesson 16: Package management — apt and which
You arrive on a fresh Ubuntu server and need nginx. which nginx returns empty output — nginx is not installed. sudo apt update downloads the list of available packages from the servers. sudo apt install -y nginx installs it. After installation, which nginx returns /usr/sbin/nginx. To remove: sudo ap
apt is the server's app store. apt update checks what's in the store. apt install downloads and installs. which checks whether the tool is already installed before you head to the store.
- which
- Searches for a command in $PATH directories and returns its path. Empty output = command not found = not installed. Example: which nginx returns /usr/sbin/nginx if nginx is installed.
- apt update
- Downloads the list of available packages from the servers (metadata only). Installs or updates nothing. Run before apt install so apt knows about current versions.
- apt install
- Downloads and installs a package and its dependencies. The -y flag auto-answers 'yes' to the confirmation prompt — useful in scripts. Example: sudo apt install -y nginx.
- apt remove / apt purge
- apt remove uninstalls a package's code but keeps config files in /etc. apt purge removes everything including config files. Both require sudo.