20 Useful PKG Command Examples to Manage Packages in FreeBSD

FreeBSD is a free and open-source Unix-like operating system based on Berkeley Software Distribution (BSD) system. It is widely used by developers, system administrators, and users who are looking for a reliable and secure operating system. One of the main features of FreeBSD is its package management system, which allows users to easily install, update, and remove software packages using the pkg command.

Basic Package Management Commands

1. Installing Packages

To install a package in FreeBSD, use the pkg install command followed by the package name ?

pkg install apache24

2. Updating All Packages

To update all installed packages to their latest versions ?

pkg upgrade

3. Searching for Packages

To search for packages by name or description ?

pkg search python

4. Listing Installed Packages

To display all installed packages with their version numbers ?

pkg info

5. Removing Packages

To remove a specific package from the system ?

pkg remove apache24

Package Information Commands

6. Displaying Package Details

To view detailed information about a specific package including description and dependencies ?

pkg info python39

7. Displaying Package Dependencies

To show what packages a specific package depends on ?

pkg info -d python39

8. Displaying Package Size

To check the disk space used by an installed package ?

pkg info -s python39

9. Displaying Package Origin

To show the ports tree origin of a package ?

pkg info -o python39

10. Displaying Package License

To view the license information for a package ?

pkg info -l python39

Advanced Package Operations

11. Listing Available Packages

To browse all packages available in the repository ?

pkg rquery -a '%n-%v'

12. Listing Packages by Size

To display installed packages sorted by their disk usage ?

pkg info -s | sort -k2 -h

13. Upgrading Specific Package

To update only a particular package instead of all packages ?

pkg upgrade python39

14. Listing Outdated Packages

To identify which installed packages have newer versions available ?

pkg version -vL=

15. Reinstalling a Package

To force reinstallation of an already installed package ?

pkg install -f python39

System Maintenance Commands

16. Cleaning Package Cache

To remove downloaded package files and free up disk space ?

pkg clean

17. Removing Orphaned Packages

To automatically remove packages that are no longer needed ?

pkg autoremove

18. Listing Packages by Category

To organize installed packages by their functional categories ?

pkg query '%n-%v %C' | sort -k2

19. Checking Package Integrity

To verify that installed packages haven't been corrupted ?

pkg check -s -a

20. Updating Package Repository

To refresh the local package repository database ?

pkg update

Package Management Best Practices

Command Type Frequency Purpose
pkg update Daily Refresh repository information
pkg upgrade Weekly Keep system secure and current
pkg autoremove Monthly Clean up unused dependencies
pkg clean Monthly Free up cache storage space

Conclusion

These 20 PKG commands provide comprehensive package management capabilities for FreeBSD systems. Regular use of update, upgrade, and cleanup commands ensures your system remains secure, current, and optimized. Mastering these commands will make you more efficient at maintaining FreeBSD installations.

Updated on: 2026-03-17T09:01:38+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements