Saltar a contenido

11 - Package Managers

What this session is

About 30 minutes. You'll learn how to install software on Linux/macOS. Every distribution has a package manager - a tool that downloads software, manages dependencies, and updates everything.

Why package managers

In Windows world, you download installers per app. On Linux you don't - instead, a central package manager lets you:

  • Install software with one command.
  • Get automatic updates for everything.
  • Resolve dependencies automatically.
  • Verify package integrity.
  • Uninstall cleanly.

Every Linux distribution has one. macOS has third-party ones (Homebrew is most popular).

apt (Debian, Ubuntu)

sudo apt update              # refresh the package list (do this first)
sudo apt upgrade             # upgrade everything installed
sudo apt install <package>   # install
sudo apt remove <package>    # uninstall (keep config files)
sudo apt purge <package>     # uninstall + remove config
sudo apt search <pattern>    # find packages matching
sudo apt show <package>      # info about a package
sudo apt list --installed    # what's installed

apt needs root for install/upgrade/remove (it modifies the system).

Common things you might install:

sudo apt install git curl wget tree htop tmux build-essential
sudo apt install python3 python3-pip python3-venv
sudo apt install nodejs npm
sudo apt install postgresql redis

build-essential brings in a C compiler and basic build tools - needed if you'll compile any software.

dnf (Fedora, RHEL, CentOS)

sudo dnf update
sudo dnf install <package>
sudo dnf remove <package>
sudo dnf search <pattern>
sudo dnf info <package>

Same shape as apt, different distros. Older Fedoras used yum; dnf is the modern replacement.

pacman (Arch)

sudo pacman -Syu              # sync + upgrade everything
sudo pacman -S <package>      # install
sudo pacman -R <package>      # remove
sudo pacman -Ss <pattern>     # search
sudo pacman -Qi <package>     # info

Arch is power-user oriented. Mentioned for completeness.

brew (macOS, also Linux)

Homebrew is macOS's most popular package manager. Doesn't need root.

brew install <package>
brew uninstall <package>
brew upgrade                  # upgrade everything
brew update                   # refresh package list (do first)
brew search <pattern>
brew info <package>
brew list                     # what's installed

Common installs:

brew install git node python tmux ripgrep fd htop
brew install --cask visual-studio-code        # GUI apps via "cask"

Install Homebrew on macOS: brew.sh. One-line installer.

What gets installed where

apt puts files in: - /usr/bin - executables. - /usr/lib - libraries. - /etc/ - config files. - /usr/share/doc/<package>/ - documentation.

brew puts everything under /opt/homebrew/ (Apple Silicon) or /usr/local/ (Intel Mac, also Homebrew on Linux).

Use which <command> to see where any installed command lives:

which python3              # /usr/bin/python3 (apt) or /opt/homebrew/bin/python3 (brew)

Language-specific package managers

For programming languages, the system package manager is usually NOT the right choice - they ship outdated versions and don't help you per-project.

Instead, use language-specific tools:

  • Python: pip (PyPI). Inside virtual environments (python -m venv .venv).
  • Node.js: npm or yarn (npm registry).
  • Rust: cargo install <crate> for Rust binaries; library deps via Cargo.toml.
  • Go: go install <package>@<version> for binaries; library deps via go.mod.
  • Ruby: gem install <pkg> (or bundler for per-project).

The pattern: system package manager for OS tools (git, curl, nano, the language itself); language package managers for libraries within your projects.

Searching for packages online

When you don't know the package name:

Or just apt search <keyword>.

A real session: set up a development environment

A typical "I just installed Linux, what do I install" sequence:

# Update everything first
sudo apt update && sudo apt upgrade -y

# Essential CLI tools
sudo apt install -y git curl wget tree htop tmux build-essential

# Language runtimes
sudo apt install -y python3 python3-pip python3-venv nodejs npm

# Better terminal tools (optional)
sudo apt install -y ripgrep fd-find bat zoxide

# Editor (if not VS Code)
sudo apt install -y vim neovim

On macOS:

brew install git curl wget tree htop tmux
brew install python node
brew install ripgrep fd bat zoxide
brew install --cask visual-studio-code

Configuration files in /etc

Most installed software puts configuration in /etc/<package>/:

/etc/nginx/                 # nginx config
/etc/postgresql/            # PostgreSQL config
/etc/ssh/sshd_config        # SSH server config
/etc/hosts                  # local DNS overrides
/etc/passwd                 # user database (not passwords)
/etc/shadow                 # password hashes (root only)
/etc/fstab                  # filesystem mounts
/etc/crontab                # system-wide scheduled jobs

Knowing where things live is half the battle. When troubleshooting, "where's the config for X?" → /etc/X/.

To edit (as root): sudo nano /etc/<package>/<file>.

Exercise

  1. Update your package lists and upgrade installed packages:

    sudo apt update && sudo apt upgrade -y     # Linux
    # or
    brew update && brew upgrade                 # macOS
    

  2. Install tree if not present, then visualize a directory:

    sudo apt install -y tree                   # or brew install tree
    tree ~/practice
    

  3. Install htop and run it:

    sudo apt install -y htop
    htop
    
    Quit with q.

  4. Search for a package by topic:

    apt search "syntax highlighting"           # or brew search
    

  5. Bonus: install one of the modern CLI replacements:

  6. ripgrep (rg) - faster grep.
  7. fd - friendlier find.
  8. bat - cat with syntax highlighting.
  9. eza - ls with colors and icons.

Try bat README.md after install. Compare to cat README.md.

What you might wonder

"What's a .deb / .rpm?" The package file format for apt / dnf respectively. You can manually install one with sudo dpkg -i pkg.deb (Debian) or sudo rpm -i pkg.rpm. Usually you don't - apt install pkgname handles everything.

"What's snap / flatpak / AppImage?" Alternative cross-distro package formats. Snaps and flatpaks bundle dependencies and run in sandboxes. AppImage is a single-file portable executable. Some software (mostly GUI apps) ships this way. For learning Linux, stick with your distro's native package manager.

"How do I install something not in the package manager?" Often the project provides a tarball or installer. Always read instructions; never run untrusted curl ... | bash from a random source.

"Why don't I need sudo for brew?" By design - Homebrew installs to a user-writable directory (/opt/homebrew or /usr/local). Avoids the "everything's root" problem of system package managers. Tradeoff: separate trees per user.

Done

  • Use your system's package manager (apt, dnf, brew).
  • Install, remove, search, update, upgrade.
  • Know where files end up and which dir holds config.
  • Distinguish system package managers from language-specific ones.

Next: Networking essentials →

Comments