Package Managers for Unix-like Systems
Outline:
- APT(Advanced Package Tool)
- pacman
Package Managers for Unix-like Systems
APT (Advanced Package Tool)
apt is a high-level command-line interface for managing packages on Debian-based systems like Ubuntu. It simplifies tasks such as installing, upgrading, and removing software.
Relationship Between dpkg, apt, and apt-get
dpkgis the low-level tool that installs, removes, and manages.debpackages locally. It does not handle dependencies or remote repositories.apt-getis a command-line front-end todpkgthat adds support for dependency resolution and remote repositories.aptis a newer, user-friendly interface introduced to unify and simplify common functions fromapt-get,apt-cache, and others. It is suitable for most daily package management tasks.
In summary:
apt→ wraps and simplifiesapt-get+apt-cacheapt-get→ older, more stable and script-friendlydpkg→ base-level tool for handling.debfiles directly
Commands
Here is the shortened command summary formatted as tables, grouped by task:
Update & Upgrade
| Command | Description |
|---|---|
sudo apt update |
Refresh package index |
sudo apt upgrade |
Upgrade installed packages |
sudo apt full-upgrade |
Upgrade with allowed removals |
sudo apt-get dist-upgrade |
Legacy version of full-upgrade |
Install
| Command | Description |
|---|---|
sudo apt install <pkg> |
Install a package |
sudo apt-get install <pkg> |
Script-friendly install |
sudo dpkg -i <file>.deb |
Install a local .deb file |
sudo apt install -f |
Fix dependencies after dpkg install |
Remove
| Command | Description |
|---|---|
sudo apt remove <pkg> |
Remove, keep config files |
sudo apt purge <pkg> |
Remove including config |
sudo apt autoremove |
Remove unused dependencies |
Query
| Command | Description |
|---|---|
apt search <term> |
Search available packages in the local package index, which a locally cached list of packages and metadata downloaded from the configured repositories. |
apt show <pkg> |
Show package details |
apt list --installed |
List installed packages |
dpkg -l |
List all installed packages |
dpkg -L <pkg> |
List files from an installed package |
Homebrew (brew)
Homebrew is a package manager for macOS. It installs software into a single prefix (managed directory tree) and exposes executables via symlinks so they are available on your PATH.
This note focuses on the mental model: where things are installed, how they are exposed, and what “sources” mean in Homebrew.
1) Directory layout: Cellar vs opt vs bin
Homebrew installs software under a single prefix (Apple Silicon: typically /opt/homebrew; Intel: /usr/local) and uses symlinks to expose commands on your PATH. It helps to separate three layers:
Cellar — the real installation directory (versioned)
Each formula is installed into a versioned path:
1
$(brew --prefix)/Cellar/<formula>/<version>/
Example (real binary location):
1
/opt/homebrew/Cellar/foo/1.2.3/bin/foo
opt— a stable symlink to the currently active version of a formulaHomebrew creates a stable symlink:
1
$(brew --prefix)/opt/<formula> -> $(brew --prefix)/Cellar/<formula>/<version>/
Example:
1
/opt/homebrew/opt/foo/bin/foo -> /opt/homebrew/Cellar/foo/1.2.3/bin/foo
Use
optpaths in scripts because the path stays constant across upgrades; only the symlink target changes.bin— user-facing commands onPATH(usually symlinks or wrappers)Executables are linked into:
1
$(brew --prefix)/bin
The command you run is typically a symlink chain:
1
2/opt/homebrew/bin/foo -> /opt/homebrew/opt/foo/bin/foo
-> /opt/homebrew/Cellar/foo/1.2.3/bin/fooSo binaries “appear” in
binbecause Homebrew links them there; the real files are still in the Cellar.
Useful checks:
1 | brew --prefix # Homebrew prefix |
2) Package types: formula vs cask
Homebrew supports two major package types because macOS software is distributed in different formats.
Formula
- Mostly CLI tools, libraries, language runtimes, and daemons.
- Installed under the Homebrew prefix (Cellar/opt/bin/lib/include/...).
1 | brew install <formula> |
Cask
- Mostly macOS GUI apps distributed as
.app/.dmg/.zip/.pkg. - Installed into
/Applications(or~/Applications).
1 | brew install --cask <cask> |
3) Tap: package definition repositories
A tap is a repository of package definitions (formulae and/or casks). Conceptually it is similar to adding a package repository.
- Defaults include
homebrew/core(formulae) andhomebrew/cask(casks). - Add a third-party tap:
1 | brew tap <org>/<repo> |
List taps:
1 | brew tap |
4) “Sources” in Homebrew: what can be mirrored
“Changing Homebrew sources” may refer to different layers:
Tap Git remotes Where formula/cask definitions are fetched from (Git repositories).
API domain (metadata) JSON metadata used by modern Homebrew (versions, bottle availability, checksums, etc.).
Bottle domain (prebuilt binaries) Where precompiled bottles are downloaded from. This is often the main speed bottleneck.
Upstream source tarballs Used only when building from source; URLs vary per package.
Inspect your current configuration (especially if you set mirrors):
1 | brew config |
5) Common commands
Search and inspect:
1 | brew search <keyword> |
List installed files for a formula:
1 | brew list <formula> |
Get the stable formula prefix (usually the opt path):
1 | brew --prefix <formula> |
6) Switching versions (when versioned formulae exist)
If Homebrew provides versioned formulae (e.g., [email protected]), you can control which version is linked into $(brew --prefix)/bin:
1 | brew unlink go |
7) Installation and mirrors (China mainland)
Homebrew installation is covered in the official documentation, so I omit it here. In mainland China, using a mirror can significantly improve reliability and download speed.
Tsinghua TUNA provides a widely used guide covering installation and mirror configuration:
- Homebrew 软件仓库(TUNA)
For an additional walkthrough (blog post):
- 如何加速 Homebrew 在 macOS 上的下载速度
Mirror configuration via environment variables (USTC example)
The following environment variables redirect different Homebrew “sources” to USTC mirrors. Add them to your shell profile (e.g., ~/.zshrc or ~/.zprofile) so they apply to every new terminal session.
1 | # Speed up Git fetches for the Homebrew software itself (Homebrew/brew) |
Verification:
1 | brew config |