Use the pkg uninstall command to remove installed packages.
When a package is uninstalled, the command output is very similar to the output when a package is installed, with “Packages to remove” instead of “Packages to install”, for example.
The --reject option of the pkg install command can also remove installed packages, as described in Rejecting a Package.
Uninstalling a package can cause a mediated link to be removed as described in Setting a Preferred Path that is Not Available: Consequences and Recovery. Use the -nv or -nvv options to check whether a mediated link will be removed.
Example 6 Undoing a Package InstallationUninstalling a package does not uninstall dependencies of that package. A user might want to continue to use the content delivered by a dependency package even if the only package that requires the dependency is uninstalled.
If you want to undo a package installation operation so that you uninstall all packages that the installation operation installed, use the pkg history command to determine exactly what was installed. See Viewing Operation History for more information.
The following command installed 18 new packages:
$ pkg install -v amp Packages to install: 18 ... Changed packages: solaris database/mysql-55 None -> 5.5.43,5.11-0.175.3.0.0.30.0:20150821T162149Z database/mysql-common None -> 5.11,5.11-0.175.3.0.0.30.0:20150821T163446Z group/feature/amp None -> 0.5.11,5.11-0.175.3.0.0.30.0:20150821T165202Z system/library/security/libmcrypt None -> 2.5.8,5.11-0.175.3.0.0.30.0:20150821T172551Z text/tidy None -> 1.0.0,5.11-0.175.3.0.0.30.0:20150821T172736Z web/php-53 None -> 5.3.29,5.11-0.175.3.1.0.2.0:20150921T191759Z web/php-53/extension/php-apc None -> 3.1.9,5.11-0.175.3.1.0.2.0:20150921T191747Z web/php-53/extension/php-idn None -> 0.2.0,5.11-0.175.3.1.0.2.0:20150921T191749Z web/php-53/extension/php-memcache None -> 3.0.6,5.11-0.175.3.1.0.2.0:20150921T191750Z web/php-53/extension/php-mysql None -> 5.3.29,5.11-0.175.3.1.0.2.0:20150921T191751Z web/php-53/extension/php-pear None -> 5.3.29,5.11-0.175.3.1.0.2.0:20150921T191752Z web/php-53/extension/php-suhosin None -> 0.9.33,5.11-0.175.3.1.0.2.0:20150921T191754Z web/php-53/extension/php-tcpwrap None -> 1.1.3,5.11-0.175.3.1.0.2.0:20150921T191755Z web/php-53/extension/php-xdebug None -> 2.2.0,5.11-0.175.3.1.0.2.0:20150921T191756Z web/php-common None -> 11.1,5.11-0.175.3.0.0.30.0:20150821T173003Z web/server/apache-22/module/apache-dtrace None -> 0.3.1,5.11-0.175.3.0.0.30.0:20150821T173046Z web/server/apache-22/module/apache-fcgid None -> 2.3.9,5.11-0.175.3.0.0.30.0:20150821T173050Z web/server/apache-22/module/apache-php53 None -> 5.3.29,5.11-0.175.3.1.0.2.0:20150921T191828Z ...
The following command shows that the list of all dependents of the amp package does not match the list of packages that were installed. Some dependents of amp were already installed, and some packages that were installed are dependents of the dependents of amp.
$ pkg contents -o type,fmri -t depend amp TYPE FMRI group web/server/apache-22 group web/server/apache-22/module/apache-dtrace group web/server/apache-22/module/apache-fcgid group web/php-53/extension/php-mysql group web/server/apache-22/module/apache-php53 group web/php-53/extension/php-apc group web/php-53 group database/mysql-55
To undo this installation if you do not have the original pkg install output, find the list of packages that were installed in the history. Use a short listing to find the installation command that you want, and then use the -l option to list exactly what was installed at that time (-t), as shown in Viewing Operation History. The list is at the end of the output under the heading End State.
$ pkg history -n 1 START OPERATION CLIENT OUTCOME 2016-10-14T07:05:53 install pkg Succeeded $ pkg history -lt 2016-10-14T07:05:53 Operation: install ... Command: /usr/bin/pkg install -v amp ... End State: None -> pkg://solaris/web/php-53@5.3.29,5.11-0.175.3.1.0.2.0:20150921T191759Z None -> pkg://solaris/group/feature/amp@0.5.11,5.11-0.175.3.0.0.30.0:20150821T165202Z None -> pkg://solaris/web/php-53/extension/php-tcpwrap@1.1.3,5.11-0.175.3.1.0.2.0:20150921T191755Z None -> pkg://solaris/web/php-53/extension/php-mysql@5.3.29,5.11-0.175.3.1.0.2.0:20150921T191751Z None -> pkg://solaris/web/server/apache-22/module/apache-php53@5.3.29,5.11-0.175.3.1.0.2.0:20150921T191828Z None -> pkg://solaris/web/server/apache-22/module/apache-dtrace@0.3.1,5.11-0.175.3.0.0.30.0:20150821T173046Z None -> pkg://solaris/web/php-53/extension/php-memcache@3.0.6,5.11-0.175.3.1.0.2.0:20150921T191750Z None -> pkg://solaris/web/php-common@11.1,5.11-0.175.3.0.0.30.0:20150821T173003Z None -> pkg://solaris/web/php-53/extension/php-xdebug@2.2.0,5.11-0.175.3.1.0.2.0:20150921T191756Z None -> pkg://solaris/database/mysql-55@5.5.43,5.11-0.175.3.0.0.30.0:20150821T162149Z None -> pkg://solaris/web/php-53/extension/php-suhosin@0.9.33,5.11-0.175.3.1.0.2.0:20150921T191754Z None -> pkg://solaris/system/library/security/libmcrypt@2.5.8,5.11-0.175.3.0.0.30.0:20150821T172551Z None -> pkg://solaris/database/mysql-common@5.11,5.11-0.175.3.0.0.30.0:20150821T163446Z None -> pkg://solaris/web/php-53/extension/php-apc@3.1.9,5.11-0.175.3.1.0.2.0:20150921T191747Z None -> pkg://solaris/web/php-53/extension/php-idn@0.2.0,5.11-0.175.3.1.0.2.0:20150921T191749Z None -> pkg://solaris/web/server/apache-22/module/apache-fcgid@2.3.9,5.11-0.175.3.0.0.30.0:20150821T173050Z None -> pkg://solaris/web/php-53/extension/php-pear@5.3.29,5.11-0.175.3.1.0.2.0:20150921T191752Z None -> pkg://solaris/text/tidy@1.0.0,5.11-0.175.3.0.0.30.0:20150821T172736ZExample 7 Specifying Multiple Packages to Uninstall
If you specify multiple packages to the pkg uninstall command, or if you specify options such as -r to perform this operation in non-global zones, you might be attempting to uninstall a package that is not installed in that image.
If you attempt to uninstall a package that is not currently installed, the pkg uninstall operation exits without uninstalling any packages.
When a package to be uninstalled does not exist in that image, a message about no matching packages is displayed for that package name. If additional packages to be uninstalled do exist in the image, no message is displayed to tell you that those packages were not uninstalled.
To uninstall all specified packages that are installed and skip the operation for any specified packages that are not installed, use the --ignore-missing option. The --ignore-missing option ignores packages that are not installed and prevents pkg uninstall from failing if some packages to uninstall are not currently installed.
In the following command, if one zone does not have the amp package installed, no packages are uninstalled, even if some zones do have amp installed.
$ pkg uninstall -r amp
In the following command, the amp package is uninstalled from any zone where it is currently installed.
$ pkg uninstall -r --ignore-missing ampExample 8 Uninstalling a Package that is Required by Another Package
Attempting to uninstall a package that is required by another installed package fails.
For example, if you try to uninstall the mysql-common package, you receive the following error message:
$ pkg uninstall mysql-common pkg uninstall: Unable to remove 'database/mysql-common@5.11-0.175.3.0.0.30.0' due to the following packages that depend on it: database/mysql-55@5.5.43-0.175.3.0.0.30.0
The following output confirms that mysql-common is required by mysql-55:
$ pkg contents -o type,pkg.name -t depend -a fmri='*mysql-common*' '*mysql-55' TYPE PKG.NAME require database/mysql-55
To uninstall mysql-common, you must uninstall both mysql-common and mysql-55. Recall that simply uninstalling mysql-55 does not uninstall the dependent package mysql-common.
$ pkg uninstall mysql-common mysql-55Example 9 Uninstalling a Package that is a group Dependency
When you uninstall a package that is a group dependency, that package is placed on the avoid list. See Avoiding Installing Some Packages in a Group Package for information about the avoid list.
$ pkg avoid $ pkg uninstall mysql-55 ... $ pkg list mysql-55 pkg list: No packages matching 'mysql-55' installed $ pkg avoid database/mysql-55 (group dependency of 'group/feature/amp')