Common commands of FreeBSD and instructions on how packages are used

Time:2019-9-14

Install packages

FreeBSD packages are currently packaged by. tgz. If you want to install a packages, you can use pkg_add, such as tgz for installing a joe:

pkg_add joe-{version}.tgz

Force installation of packages
Because some packages have dependencies with other packages, those packages must be installed before they can be installed properly. If you need to force packages, you may not need to install those dependent packages, but it is important to note that the results of the force installation may lead to abnormal execution or operation. The instructions for forcing packages to be installed are as follows, such as forcing a Joe tgz to be installed:
pkg_add -f joe-{version}.tgz  

Query the dependencies between packages and other packages

Because some packages have dependencies with other packages, those packages must be installed before they can be installed properly. The instructions for querying the dependencies between packages and other packages are as follows, such as querying other packages that are dependent on portupgrade:

pkg_info -r portupgrade-{version}.tgz  

Remote installation packages

There are two settings, the first is PACKAGEROOT, such as:

setenv PACKAGEROOT ftp://ftp.cn.freebsd.org/# Another way to set PACKAGEROOT as ftp.cn.freebsd.org platform is to set PACKAGESITE. The advantage is that if the storage of packages on the platform is not in line with the requirements.
Official settings or you want to specify a path for yourself. Take the current pakcages of ftp.cn.freebsd.org i386 as an example:

setenv PACKAGESITE ftp://ftp.cn.freebsd.org/pub/FreeBSD/ports/i386/packages-current/Latest/

Either way, the next steps are the same. When installing packages later, such as portupgrade, then:

pkg_add -r portupgrade  
The system will automatically download and install all portupgrade-dependent packages at ftp.cn.freebsd.org.

Query which suites are currently installed in the system

Query all packages currently installed in the system:
pkg_info  

Query whether the current system has installed this keyword Suite
pkg_info | grep  

Query which suites a file belongs to

If you want to query which Suite / usr / local / bin / Joe belongs to, then:

pkg_info -W /usr/local/bin/joe  
If no information is returned, it means that the file is built-in by FreeBSD.

Query which files are installed in a suite

If you want to query which files are included in the Joe installed on the current system, then:

pkg_info -L /var/db/pkg/joe-{version}

List all upgradable ports

Ports collections are updated very quickly. After each update of ports collections, new versions will appear, which can make the system organize itself and provide a list of upgradable suites.

pkg_version –c

Remove installed ports
Take editors/joe as an example, then:
cd /usr/ports/editors/joe/
make deinstall  
Or use pkg_delete
cd /var/db/pkg/
pkg_delete joe-{version}  
Sometimes the dependencies between packages can not be removed directly, if forced, then:
cd /var/db/pkg/
Pkg_delete-f Joe – {version} but it is likely to cause problems with other suites.

Remove the dependent ports together
Take sysutils/portupgrade as an example.
cd /usr/ports/sysutils/portupgrade/
make deinstall-depends  
Before performing this step, please note whether the package that should be protected will be removed.
Or use pkg_delete
cd /var/db/pkg/
pkg_delete -r portupgrade-{version}  

Packing an installed port

If a package is installed, it is not packed beforehand and wants to be packed afterwards, then:
Take editors/joe for example

cd /var/db/pkg/
Pkg_create-b joe-{version number}
The installed ports are packaged and placed in the / var / db / PKG / directory.

` What’s the difference between make deinstall and `pkg_delete’?

Simply put, `make deinstall’removes the port and does not refer to its dependent/related ports. ` pkg_delete’refers to its dependent/related ports before removing the ports, and `pkg_delete’ supports wild cards. If you want to remove all ports at the beginning of p, then:

cd /var/db/pkg/
pkg_delete p*
It should be noted that if `make de Install’is used, it is better to determine the version currently installed in the system, which is in line with the version shown in the ports collection, otherwise unexpected errors may occur; and `pkg_delete’ is not a problem because the version installed in the system is deleted directly.

Therefore, in other words, `make deinstall’or `pkg_delete’ can be used when the version installed in the system conforms to the version in ports collections, otherwise `pkg_delete’is preferable.

Packing an installed port

If a package is installed, it is not packed beforehand and wants to be packed afterwards, then:
Take editors/joe for example

cd /var/db/pkg/
Pkg_create-b joe-{version number}
The installed ports are packaged and placed in the / var / db / PKG / directory.