.\"
.\" FreeBSD pkg - a next generation package for the installation and maintenance
.\" of non-core utilities.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\"
.\" @(#)pkg.8
.\"
.Dd April 17, 2026
.Dt PKG-DELETE 8
.Os
.Sh NAME
.Nm "pkg delete"
.Nd deletes packages from the database and the system
.Sh SYNOPSIS
.Nm
.Op Fl DfnqRy
.Op Fl Cgix
.Op Fl G Ar exclude-glob
.Ar pkg-name ...
.Nm
.Op Fl Dnqy
.Op Fl G Ar exclude-glob
.Fl a
.Pp
.Nm
.Op Cm --{no-scripts,force,dry-run,quiet,recursive,yes,autoremove}
.Op Cm --{case-sensitive,glob,case-insensitive,regex}
.Ar pkg-name ...
.Nm
.Op Cm --{no-scripts,dry-run,quiet,yes,autoremove}
.Cm --all
.Sh DESCRIPTION
.Nm
is used for deleting installed packages from the system.
.Nm
creates a work-list of all the installed packages matching the package
names on the command line.
The list is presented to the user.
If the user confirms that they do want to remove those packages, or
if the
.Cm ASSUME_ALWAYS_YES
configuration option is set,
.Nm
proceeds to remove the listed packages.
.Pp
If the set of packages to be deleted would leave installed packages
with unfulfilled dependencies,
.Nm
will add the packages with unfulfilled dependencies to the list of
packages to be deleted, unless forced to proceed without deleting any
other packages by the
.Fl f
option.
.Pp
.Nm
avoids deleting itself unless named specifically on the command line.
So, for instance,
.Nm Fl a
will delete all packages except for the
.Xr pkg 8
package.
To force all packages to be removed without exception, use
.Nm Fl fa .
.Sh OPTIONS
The following options are supported by
.Nm :
.Bl -tag -width recursive
.It Fl a , Cm --all
Deletes all installed packages except for
.Xr pkg 8
from the system and cleans the database of information related to removed
packages.
.It Fl C , Cm --case-sensitive
Make the standard or regular expression
.Fl ( x )
matching against
.Ar pkg-name
case sensitive.
This is the default, unless modified by setting
.Ev CASE_SENSITIVE_MATCH
to false in
.Pa pkg.conf .
.It Fl D , Cm --no-scripts
If a deinstallation script exists for a given package, do not execute it.
.It Fl f , Cm --force
Forces packages to be removed despite leaving unresolved dependencies.
.It Fl G Ar glob , Cm --exclude-glob Ar glob
Exclude packages whose names match the given shell glob pattern from
deletion.
This option may be specified multiple times.
It is particularly useful in combination with
.Fl a
to delete all packages except those matching the exclusion pattern(s).
In combination with the
.Fl a
or
.Fl -all
flag, causes
.Xr pkg 8
to be removed as well as all other packages.
.It Fl g , Cm --glob
Treat the package names as shell glob patterns.
.It Fl i , Cm --case-insensitive
Make the standard or regular expression
.Fl ( x )
matching against
.Ar pkg-name
case insensitive.
.It Fl n , Cm --dry-run
Dry run mode.
The list of packages to delete is always printed, but no packages are
actually deleted.
.It Fl q , Cm --quiet
Force quiet output, except where
.Fl n
is also used, when
.Nm
will show the list of packages to be deleted.
.It Fl R , Cm --recursive
Delete all packages that require the listed packages as well.
.It Fl x , Cm --regex
Treat the package names as regular expressions according to the
"modern" or "extended" syntax of
.Xr re_format 7 .
.It Fl y , Cm --yes
Assume yes when asked for confirmation before package deletion.
.It Cm --autoremove
After deleting the requested packages, automatically remove any orphaned
packages that were installed as dependencies and are no longer required.
This is equivalent to running
.Xr pkg-autoremove 8
after the deletion.
Can also be enabled permanently via the
.Cm AUTOREMOVE
option in
.Xr pkg.conf 5 .
.It Cm --script-no-exec
Do not execute the pre-deinstall and post-deinstall scripts but still log
the scripts in the package database for future reference.
Unlike
.Fl D ,
which prevents scripts from both running and being recorded,
.Cm --script-no-exec
only suppresses execution.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm .
See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev HANDLE_RC_SCRIPTS
.It Ev PKG_DBDIR
.It Ev CASE_SENSITIVE_MATCH
.El
.Sh FILES
See
.Xr pkg.conf 5 .
.Sh EXAMPLES
Delete all packages except those from the FreeBSD base system:
.Dl # pkg delete -af -G \(dqFreeBSD-*\(dq
.Pp
Delete all packages except base and pkg packages:
.Dl # pkg delete -af -G \(dqFreeBSD-*\(dq -G \(dqpkg-*\(dq
.Sh SEE ALSO
.Xr pkg_checksum 3 ,
.Xr pkg_create 3 ,
.Xr pkg_printf 3 ,
.Xr pkg_repo_create 3 ,
.Xr pkg_repos 3 ,
.Xr pkg-keywords 5 ,
.Xr pkg-lua-script 5 ,
.Xr pkg-repository 5 ,
.Xr pkg-script 5 ,
.Xr pkg-triggers 5 ,
.Xr pkg.conf 5 ,
.Xr pkg 8 ,
.Xr pkg-add 8 ,
.Xr pkg-alias 8 ,
.Xr pkg-annotate 8 ,
.Xr pkg-audit 8 ,
.Xr pkg-autoremove 8 ,
.Xr pkg-check 8 ,
.Xr pkg-checksum 8 ,
.Xr pkg-clean 8 ,
.Xr pkg-config 8 ,
.Xr pkg-create 8 ,
.Xr pkg-fetch 8 ,
.Xr pkg-help 8 ,
.Xr pkg-info 8 ,
.Xr pkg-install 8 ,
.Xr pkg-key 8 ,
.Xr pkg-lock 8 ,
.Xr pkg-plugins 8 ,
.Xr pkg-query 8 ,
.Xr pkg-register 8 ,
.Xr pkg-repo 8 ,
.Xr pkg-repositories 8 ,
.Xr pkg-rquery 8 ,
.Xr pkg-rwhich 8 ,
.Xr pkg-search 8 ,
.Xr pkg-set 8 ,
.Xr pkg-shell 8 ,
.Xr pkg-shlib 8 ,
.Xr pkg-ssh 8 ,
.Xr pkg-stats 8 ,
.Xr pkg-triggers 8 ,
.Xr pkg-unregister 8 ,
.Xr pkg-update 8 ,
.Xr pkg-updating 8 ,
.Xr pkg-upgrade 8 ,
.Xr pkg-version 8 ,
.Xr pkg-which 8