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

  • dpkg is the low-level tool that installs, removes, and manages .deb packages locally. It does not handle dependencies or remote repositories.
  • apt-get is a command-line front-end to dpkg that adds support for dependency resolution and remote repositories.
  • apt is a newer, user-friendly interface introduced to unify and simplify common functions from apt-get, apt-cache, and others. It is suitable for most daily package management tasks.

In summary:

  • apt → wraps and simplifies apt-get + apt-cache
  • apt-get → older, more stable and script-friendly
  • dpkg → base-level tool for handling .deb files 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

5) Common commands

Search and inspect:

brew search <keyword>
brew info <name>

List installed files for a formula:

brew list <formula>

Get the stable formula prefix (usually the opt path):

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:

brew unlink go
brew link --overwrite [email protected]

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.

# Speed up Git fetches for the Homebrew software itself (Homebrew/brew)
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"

# Speed up Git fetches for the Core tap (homebrew/core), which contains most formula definitions
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"

# Speed up bottle downloads (prebuilt binaries). This is often the biggest performance win.
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"

# Speed up Homebrew’s JSON API (metadata for versions/bottles/checksums)
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"

# Suppress Homebrew warnings/hints about custom HOMEBREW_* environment variables
export HOMEBREW_NO_ENV_HINTS="1"

Verification:

brew config
env | grep '^HOMEBREW_' | sort

git -C "$(brew --repo)" remote -v
# If core is present locally:
git -C "$(brew --repo homebrew/core)" remote -v 2>/dev/null

To temoprally switch back to official source, i.e., disabling mirrors, run in current shell session:

unset HOMEBREW_BREW_GIT_REMOTE
unset HOMEBREW_CORE_GIT_REMOTE
unset HOMEBREW_API_DOMAIN
unset HOMEBREW_BOTTLE_DOMAIN

then:

brew update