Guide | This article will explain how to manage installation packages with the help of PKG package manager |
System environment
FreeBSD 12.2-RELEASE
Search software by PKG command
1. The easiest way to search for applications in FreeBSD is through the PKG command line. Syntax format:, the pkg serach [package_name]
following is the installation package for searching vim melon:
root@freebsd:~ # pkg search vim
2. If you want to see which category the package belongs to, use the -o option, as shown in the following example:
root@freebsd:~ # pkg search -o mariadb
Use PKG management software
1. Use the pkg install [package_name]
command to install the package:
root@freebsd:~ # pkg install -y lrzsz
2. If you need to query the installed installation package information, use the pkg info [package_name]
option, use the following command:
root@freebsd:~ # pkg info pkg
Note: If the package is not installed in the system, the pkg info command will display "No matching package":
3. In order to list all installed packages in FreeBSD, execute the pkg info command without any options. It can be used in conjunction with grep
and less
other commands.
root@freebsd:~ # pkg info
4. Use the pkg remove [package_name]
option to delete unused installation packages:
root@freebsd:~ # pkg remove -y lrzsz
5. If you want to prevent deleting or modifying the installed software package, you can use the lock option of the pkg command, as shown in the figure below.
root@freebsd:~ # pkg lock nginx
You can see in the picture that the file is locked and cannot be removed every time. If you need to unlock, use the pkg unlock [package_name]
command to unlock.
root@freebsd:~ # pkg unlock nginx
nginx-1.18.0_25,2: unlock this package? [y/N]: y
Unlocking nginx-1.18.0_25,2
6. To ensure that the software warehouse and all installed software packages are the latest version or the latest security patches, use the pkg update
update warehouse and use the pkg upgrade
upgrade to the latest version.
root@freebsd:~ # pkg update
root@freebsd:~ # pkg upgrade -y
7. To display information about remote warehouses and locally installed programs, such as how many software packages are installed in the system and how much disk space the installed software occupies, execute the following command.
root@freebsd:~ # pkg stats
8. To delete all dependent packages left by the installed packages in the system, use the following command:
root@freebsd:~ # pkg autoremove -y
9. If you need to delete the cache of the downloaded installation package, you can use a pkg clean -a -y
command to automatically clear it, and use a pkg clean -a -n
trial run before running it.
root@freebsd:~ # pkg clean -a -n
root@freebsd:~ # pkg clean -a -y
to sum up
This article is about how to manage installation packages with the help of PKG package manager. Linux should be learned like this