Remove Unwanted/Unused Dependencies in FreeBSD package

I deleted a package using the ‘pkg remove foo‘ command. However, it left over 30+ dependencies. Theses dependencies not needed by any other package on a FreeBSD Unix system and just taking space on my hard drive. How do I remove unwanted or unused dependencies in FreeBSD 11.x server?

You need to pass the autoremove option to the pkg command for removing orphan packages, which were installed during dependency resolution and are no longer needed. Software dependency is nothing but software relies on another one. For example, bash package depending upon Readline library. The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in. So when you add bash shell in FreeBSD, the GNU Readline get installed too.
How To Remove Unwanted / Unused Dependencies in FreeBSD pkg Command
This quick tutorial explains how to removes orphan packages on a FreeBSD system.

ADVERTISEMENTS

Syntax – Delete unused dependencies in FreeBSD using pkg

The syntax is
pkg autoremove
pkg -n autoremove
pkg -y autoremove

Where,

  1. -n or --dry-run: Dry-run mode. The list of changes to packages is always printed, but no changes are actually made.
  2. -y : Assume yes when asked for confirmation before package autoremoval.
  3. -q : Do not display much info be quite i.e. force quite output on the screen.

Examples – Removing unused dependencies in FreeBSD

Type the following command:
# pkg autoremove
OR
$ sudo pkg autoremove
Sample outputs:

Password:
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 33 packages:
 
Installed packages to be REMOVED:
	curl-7.56.0
	libgit2-0.25.1_1
	py36-pygit2-0.25.1
	ca_root_nss-3.32.1
	python36-3.6.2_1
	py36-setuptools-36.2.2
	py36-pycparser-2.10
	py36-cffi-1.7.0
	py36-cryptography-2.0.3
	py36-openssl-17.3.0
	py36-urllib3-1.22
	py36-requests-2.18.1_1
	py36-idna-2.5
	py36-six-1.11.0
	py36-pyasn1-0.2.2
	py36-pysocks-1.6.7
	py36-chardet-3.0.4
	py36-certifi-2017.7.27.1
	py36-humanfriendly-4.4.1
	py36-coloredlogs-7.3
	py36-texttable-0.9.1
	py36-tqdm-4.18.0
	py36-verboselogs-1.6
	py36-pytest-runner-2.11.1
	py36-libzfs-1.0.20170814
	py36-click-6.7
	python3-3_3
	libffi-3.2.1_1
	libnghttp2-1.26.0
	libssh2-1.8.0,3
	uclcmd-0.1_2
	libucl-0.8.0
	readline-7.0.3
 
Number of packages to be removed: 33
 
The operation will free 134 MiB.
 
Proceed with deinstalling packages? [y/N]: y
[1/33] Deinstalling py36-requests-2.18.1_1...
[1/33] Deleting files for py36-requests-2.18.1_1: 100%
[2/33] Deinstalling py36-urllib3-1.22...
[2/33] Deleting files for py36-urllib3-1.22: 100%
[3/33] Deinstalling py36-openssl-17.3.0...
[3/33] Deleting files for py36-openssl-17.3.0: 100%
[4/33] Deinstalling py36-pygit2-0.25.1...
[4/33] Deleting files for py36-pygit2-0.25.1: 100%
[5/33] Deinstalling py36-cryptography-2.0.3...
[5/33] Deleting files for py36-cryptography-2.0.3: 100%
[6/33] Deinstalling py36-cffi-1.7.0...
[6/33] Deleting files for py36-cffi-1.7.0: 100%
[7/33] Deinstalling py36-coloredlogs-7.3...
[7/33] Deleting files for py36-coloredlogs-7.3: 100%
[8/33] Deinstalling py36-pycparser-2.10...
[8/33] Deleting files for py36-pycparser-2.10: 100%
[9/33] Deinstalling py36-idna-2.5...
[9/33] Deleting files for py36-idna-2.5: 100%
[10/33] Deinstalling py36-six-1.11.0...
[10/33] Deleting files for py36-six-1.11.0: 100%
[11/33] Deinstalling py36-pyasn1-0.2.2...
[11/33] Deleting files for py36-pyasn1-0.2.2: 100%
[12/33] Deinstalling py36-pysocks-1.6.7...
[12/33] Deleting files for py36-pysocks-1.6.7: 100%
[13/33] Deinstalling py36-chardet-3.0.4...
[13/33] Deleting files for py36-chardet-3.0.4: 100%
[14/33] Deinstalling py36-certifi-2017.7.27.1...
[14/33] Deleting files for py36-certifi-2017.7.27.1: 100%
[15/33] Deinstalling py36-humanfriendly-4.4.1...
[15/33] Deleting files for py36-humanfriendly-4.4.1: 100%
[16/33] Deinstalling py36-texttable-0.9.1...
[16/33] Deleting files for py36-texttable-0.9.1: 100%
[17/33] Deinstalling py36-tqdm-4.18.0...
[17/33] Deleting files for py36-tqdm-4.18.0: 100%
[18/33] Deinstalling py36-verboselogs-1.6...
[18/33] Deleting files for py36-verboselogs-1.6: 100%
[19/33] Deinstalling py36-pytest-runner-2.11.1...
[19/33] Deleting files for py36-pytest-runner-2.11.1: 100%
[20/33] Deinstalling py36-libzfs-1.0.20170814...
[20/33] Deleting files for py36-libzfs-1.0.20170814: 100%
[21/33] Deinstalling py36-click-6.7...
[21/33] Deleting files for py36-click-6.7: 100%
[22/33] Deinstalling libgit2-0.25.1_1...
[22/33] Deleting files for libgit2-0.25.1_1: 100%
[23/33] Deinstalling py36-setuptools-36.2.2...
[23/33] Deleting files for py36-setuptools-36.2.2: 100%
[24/33] Deinstalling python3-3_3...
[24/33] Deleting files for python3-3_3: 100%
[25/33] Deinstalling curl-7.56.0...
[25/33] Deleting files for curl-7.56.0: 100%
[26/33] Deinstalling python36-3.6.2_1...
[26/33] Deleting files for python36-3.6.2_1: 100%
[27/33] Deinstalling uclcmd-0.1_2...
[27/33] Deleting files for uclcmd-0.1_2: 100%
[28/33] Deinstalling ca_root_nss-3.32.1...
[28/33] Deleting files for ca_root_nss-3.32.1: 100%
[29/33] Deinstalling libffi-3.2.1_1...
[29/33] Deleting files for libffi-3.2.1_1: 100%
[30/33] Deinstalling libnghttp2-1.26.0...
[30/33] Deleting files for libnghttp2-1.26.0: 100%
[31/33] Deinstalling libssh2-1.8.0,3...
[31/33] Deleting files for libssh2-1.8.0,3: 100%
[32/33] Deinstalling libucl-0.8.0...
[32/33] Deleting files for libucl-0.8.0: 100%
[33/33] Deinstalling readline-7.0.3...
[33/33] Deleting files for readline-7.0.3: 100%

How to remove unused Dependencies in FreeBSD with pkg Command

In this example I am going to remove or delete a package named py36-iocage-0.9.10:
# pkg remove py36-iocage-0.9.10
Sample outputs:

Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):
 
Installed packages to be REMOVED:
	py36-iocage-0.9.10
 
Number of packages to be removed: 1
 
Proceed with deinstalling packages? [y/N]: y
[1/1] Deinstalling py36-iocage-0.9.10...
[1/1] Deleting files for py36-iocage-0.9.10: 100%

Next I am going to removes orphan packages by typing the following pkg command:
# pkg autoremove -y
Sample session:

Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 22 packages:
 
Installed packages to be REMOVED:
	py36-cryptography-2.1.4
	py36-openssl-17.5.0_1
	py36-urllib3-1.22
	py36-requests-2.18.4
	py36-asn1crypto-0.22.0
	py36-certifi-2018.1.18
	py36-cffi-1.11.2
	py36-chardet-3.0.4
	py36-click-6.7
	py36-coloredlogs-9.0
	py36-dulwich-0.15.0
	py36-humanfriendly-4.9
	py36-idna-2.6
	py36-libzfs-1.0.20171215
	py36-pycparser-2.18
	py36-pysocks-1.6.8
	py36-pytest-runner-2.11.1
	py36-six-1.11.0
	py36-texttable-1.2.1
	py36-tqdm-4.19.6
	py36-setuptools-39.0.1
	python36-3.6.4
 
Number of packages to be removed: 22
 
The operation will free 126 MiB.
 
Proceed with deinstalling packages? [y/N]: y
[1/22] Deinstalling py36-requests-2.18.4...
[1/22] Deleting files for py36-requests-2.18.4: 100%
[2/22] Deinstalling py36-urllib3-1.22...
...
.....
..
[20/22] Deleting files for py36-tqdm-4.19.6: 100%
[21/22] Deinstalling py36-setuptools-39.0.1...
[21/22] Deleting files for py36-setuptools-39.0.1: 100%
[22/22] Deinstalling python36-3.6.4...
[22/22] Deleting files for python36-3.6.4: 100%

The above command will help you free up disk space on your server. It also helps with avoiding software vulnerabilities. For more info see this page or read the man page by typing the following command:
$ man pkg-autoremove

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.