Examples of using pkg package manager in FreeBSD

Guide This article will explain how to manage installation packages with the help of PKG package manager

System environment

FreeBSD 12.2-RELEASE
Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD

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

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
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

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD

Use PKG management software

1. Use the pkg install [package_name]command to install the package:

root@freebsd:~ # pkg install -y lrzsz

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
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

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
Note: If the package is not installed in the system, the pkg info command will display "No matching package":
Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
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 grepand lessother commands.

root@freebsd:~ # pkg info

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
4. Use the pkg remove [package_name]option to delete unused installation packages:

root@freebsd:~ # pkg remove -y lrzsz

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
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

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
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 updateupdate warehouse and use the pkg upgradeupgrade to the latest version.

root@freebsd:~ # pkg update
root@freebsd:~ # pkg upgrade -y

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
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

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
8. To delete all dependent packages left by the installed packages in the system, use the following command:

root@freebsd:~ # pkg autoremove -y

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
9. If you need to delete the cache of the downloaded installation package, you can use a pkg clean -a -ycommand to automatically clear it, and use a pkg clean -a -ntrial run before running it.

root@freebsd:~ # pkg clean -a -n

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD

root@freebsd:~ # pkg clean -a -y

Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD
Examples of using the pkg package manager in FreeBSD Examples of using the pkg package manager in FreeBSD

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

Guess you like

Origin blog.csdn.net/Linuxprobe18/article/details/111941947