SH

Package Management

Bash & Linux · 5 entries

APT (Debian, Ubuntu)

syntax
sudo apt update
sudo apt install package
sudo apt remove package
example
sudo apt update && sudo apt upgrade -y
sudo apt install nginx postgresql-16
sudo apt search image-editor
apt list --installed | grep python

Note Always run apt update before installing to refresh package lists. apt is for Debian-based distributions (Debian, Ubuntu, Linux Mint, Pop!_OS). -y auto-confirms prompts. Use apt autoremove to clean up unused dependencies.

Homebrew (macOS, Linux)

syntax
brew install formula
brew install --cask app
brew update && brew upgrade
example
brew install jq ripgrep tree
brew install --cask visual-studio-code
brew list
brew cleanup

Note Homebrew is the dominant package manager on macOS and also runs on Linux. Formulae are CLI tools; casks are GUI applications. Run brew update to refresh, brew upgrade to update all installed packages. brew cleanup removes old versions to free space.

YUM / DNF (RHEL, Fedora, CentOS)

syntax
sudo dnf install package
sudo yum install package
example
sudo dnf update
sudo dnf install httpd mariadb-server
sudo dnf search editor
sudo dnf remove old-package

Note dnf is the modern replacement for yum (Fedora 22+, RHEL 8+, CentOS Stream). yum still works on older CentOS/RHEL 7. Both resolve dependencies automatically. Use dnf list installed to see what is installed.

Snap (Cross-Distribution)

syntax
sudo snap install package
snap list
example
sudo snap install code --classic
sudo snap install node --channel=20/stable
snap list
sudo snap refresh

Note --classic is required for snaps that need broader system access (like editors and compilers). Snaps auto-update in the background. Available on Ubuntu by default and installable on most Linux distributions. snap refresh manually triggers updates.

Locate Installed Binaries

syntax
which command
whereis command
command -v command
example
which python3
whereis gcc
command -v node || echo 'node not found'
output
/usr/bin/python3
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz

Note which shows the full path of a command. whereis also shows man pages and source locations. In scripts, prefer command -v over which because it is POSIX-compliant and handles aliases/builtins correctly.