How To Remove Unwanted/Unused Dependencies in FreeBSD pkg Command

in Categories , , , last updated October 26, 2017

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.
pkg autoremove - removes orphan packages
This quick tutorial explains how to removes orphan packages on a FreeBSD system.

Syntax

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

Where,

  1. -n : 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.

Examples

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%

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 0 comments/add one below):