Introduction to pkg
pkg is FreeBSD's official package manager for installing pre-built binary packages. It's the fastest way to install software on FreeBSD.
Initial Setup
# Bootstrap pkg (first time only)
pkg bootstrap
# Or let it auto-bootstrap on first use
pkg updateRepository Configuration
# Repository config location
/etc/pkg/FreeBSD.conf # Default repo
/usr/local/etc/pkg/repos/ # Custom repos
# View current repository
pkg -vv | grep -A5 "Repositories"
# Use quarterly (stable) vs latest packages
# Edit /etc/pkg/FreeBSD.conf:
FreeBSD: {
url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly",
# or "latest" for newest versions
}Searching for Packages
# Search by name
pkg search nginx
# Search with description
pkg search -D "web server"
# Search exact name
pkg search -e nginx
# Show package origin
pkg search -o nginx
# Output: www/nginxInstalling Packages
# Install single package
pkg install nginx
# Install multiple packages
pkg install nginx mysql80-server php83
# Install without confirmation
pkg install -y nginx
# Install specific version (if available)
pkg install nginx-1.24Updating Packages
# Update package database
pkg update
# Upgrade all packages
pkg upgrade
# Upgrade specific package
pkg upgrade nginx
# Force upgrade (reinstall)
pkg upgrade -f nginxRemoving Packages
# Remove package
pkg delete nginx
# Remove with dependencies (unused)
pkg delete -y nginx
pkg autoremove
# Remove all packages (careful!)
pkg delete -a
# Force removal
pkg delete -f nginxPackage Information
# List installed packages
pkg info
# Detailed package info
pkg info nginx
# List package files
pkg info -l nginx
# Package dependencies
pkg info -d nginx
# Reverse dependencies (what depends on this)
pkg info -r nginx
# Package size
pkg info -s nginxPackage Queries
# Which package owns a file
pkg which /usr/local/bin/nginx
# List packages by size
pkg info -sa | sort -k2 -h
# List manually installed packages
pkg query -e '%a = 0' '%n-%v'
# Check for vulnerabilities
pkg audit -FMaintenance Commands
# Clean package cache
pkg clean
# Remove orphaned dependencies
pkg autoremove
# Check package integrity
pkg check -s -a
# Lock package (prevent upgrades)
pkg lock nginx
pkg unlock nginx
# List locked packages
pkg lock -lOffline Package Management
# Download package without installing
pkg fetch nginx
# Create package from installed software
pkg create nginx
# Install from local file
pkg add /path/to/nginx-1.24.txzTroubleshooting
# Force repository update
pkg update -f
# Reinstall package
pkg install -f nginx
# Fix broken packages
pkg check -B -a
# View verbose output
pkg -d install nginx - freebsd
- pkg
- packages
- software
- installation