How to list and uninstall installed Mac OS X packages command

how-to-list-and-remove-packages-on-Mac-OS-X-MacBook-Air-Pro-notebooks-with-commands-Terminal
1. Listing All installed packages (.pkg) files on Mac OS X

If you are used to Linux package management (with dpkg .deb package tool or Redhat's .rpm package manager rpm command) and out of a suddeny you have to use for some time or permanently choose to migrate to Mac OS X and joined the Jailed closed Computer model of Mr. Steve Jobs.

As a Linux command addict,yYou might be wondering on how to list all installed packages on Mac OS with a command just like you use Debian / Ubuntus terminal to list installed packages and their overall state for example with dpkg with:

dpkg -l

or Fedora / CentOS to list all installed packages you're pretty much accustomed to:
 

rpm -qa

The same is possible in Mac OS X by opening Terminal and running cmd:

 

MacBook-Air:Volumes root# pkgutil –pkgs

om.apple.pkg.OSX_10_13_IncompatibleAppList.16U1254
com.apple.pkg.MRTConfigData.16U4001
com.apple.pkg.ChineseWordlistUpdate.14U1355
com.apple.pkg.GatekeeperConfigData.16U1300
com.apple.pkg.MRTConfigData.16U4003
com.apple.pkg.ChineseWordlistUpdate.14U1356
com.apple.pkg.ChineseWordlistUpdate.14U1346
com.apple.pkg.GatekeeperConfigData.16U1259
com.apple.pkg.GatekeeperConfigData.16U1265
com.apple.pkg.XProtectPlistConfigData.16U4009
com.apple.pkg.ChineseWordlistUpdate.14U1353
com.apple.pkg.ChineseWordlistUpdate.14U1347
com.apple.pkg.ChineseWordlistUpdate.14U1351
com.apple.pkg.MRTConfigData.16U4038
com.apple.pkg.iTunesX.12.7.3.delta
com.apple.pkg.XProtectPlistConfigData.14U4058
com.apple.pkg.GatekeeperConfigData.16U1138
com.apple.pkg.MLVUpdate_en_GB_daniel.16U1127
com.apple.pkg.EmbeddedOSFirmware
com.apple.pkg.MRTConfigData.16U4005
com.apple.pkg.ChineseWordlistUpdate.14U1323
com.apple.pkg.GatekeeperConfigData.16U1572
com.apple.pkg.iTunesX.12.7.delta
com.apple.pkg.MRT.14U2321

For the sake of convenience run it with a pipe to less cmd:

MacBook-Air:Volumes root# pkgutil –pkgs | less

To find whether a package with a certain name is installed or not

mac-os-x-listing-installed-operating-system-packages-with-pkgutil-command

MacBook-Air:Volumes root# pkgutil –pkgs|grep -i oracle
com.oracle.jre|


To further list the content of the package (the package files contained and directory structure etc.)

 

MacBook-Air:Volumes root# pkgutil –files the-package-name.pkg

 

this is like the Linux equivalent of
dpkg -L packagename and rpm -qa rpm-packagename:

Checking the package directory location on Mac OS is done with:

 

MacBook-Air:Volumes root#  pkgutil –pkg-info com.oracle.jre
package-id: com.oracle.jre
version: 1.0
volume: /
location: Library/Internet Plug-Ins/JavaAppletPlugin.plugin
install-time: 1523533193

 


2. Deleting a Mac OS X package .pkg 
 

After reviewing the .pkg file content for smaller sized packages the best way to remove it is to manually remove all files belonging to the package (but before make sure you are not deleting an important packageand have visually closely inspected them otherwise you might break badly your Mac OS X  …) you can run below 2 commands to delete package files and directory:

 

# pkgutil –only-files –files the-package-name.pkg | tr 'n' '' | xargs -n 1 -0 sudo rm -f
# pkgutil –only-dirs –files the-package-name.pkg | tail -r | tr 'n' '' | xargs -n 1 -0 sudo rmdir

 

Once you have removed the files you can remove the receipt (e.g. remove it from Mac package database), with:
 

# pkgutil –forget the-package-name.pkg

 

pkgutil –forget is useful if you get errors during removal attempt with pkgutil –only-files … , pkgutil –only-dirs …. cmds.
 

Note that to remove a package you have to be root  or run the commands via sudo with admin privileges if you have it installed and using it.

When removing the files be extremely careful as some of the packages you might try to remove might be updating important Mac OS X system components or used as a backbone for the overall Mac OS GUI / background operations thus removing a system related package might leave your MacBook unbootable because of the removal of the necessery component …

If you get some errors while issuing some of the 2 above commands like:

"Operation not permitted when trying to uninstall" this is because  the command or directory you're trying to remove is in current use by a running process on the Mac OS or because the file or directory has a special set permissions to prevent them from easy removal (as a precaution OS safety measures).

You might wonder what might be the purpose of a manual command removal of Mac package but, If you have to regularly delete Mac OS X packages by scripting the removal of unnecessery packages or Mac OS X updates on a many numbers of computers to automate removal jobs.
I've found also a github repository bash shell script that is automating the process of removal and could even save further time if in need to script a package information about Macs and be able to easily manage packages of mac Desktops via (lets say SSH), check out pkg-remove.sh script here.

Share this on:

More helpful Articles

Download PDFDownload PDF

Tags: , , , ,

Leave a Reply

CommentLuv badge