71

Despite opinions to the contrary, not all packages are installed cleanly in only one directory. Is there a way to reverse the install process of a pkg file, preferably with the original package (or from a repository of information about installed packages)?

Specifically I've installed the PowerPC MySQL 5.4.1 package on an intel MacBook, and would like to cleanly reverse that, recovering the 5.1 x86 install I can see is still there, but not working properly now.

5 Answers 5

119

https://wincent.com/wiki/Uninstalling_packages_(.pkg_files)_on_Mac_OS_X describes how to uninstall .pkg using native pkgutil.

Modified excerpt

$ pkgutil --pkgs # list all installed packages
$ pkgutil --files the-package-name.pkg # list installed files

After visually inspecting the list of files you can do something like:

$ pkgutil --pkg-info the-package-name.pkg # check the location
$ cd / # assuming the package is rooted at /...
$ pkgutil --only-files --files the-package-name.pkg | tr '\n' '\0' | xargs -n 1 -0 sudo rm -f
$ pkgutil --only-dirs --files the-package-name.pkg | tail -r | tr '\n' '\0' | xargs -n 1 -0 sudo rmdir

Needless to say, extreme care should always be taken when removing files with root privileges. Particularly, be aware that some packages may update shared system components, so uninstalling them can actually break your system by removing a necessary component.

For smaller packages it is probably safer to just manually remove the files after visually inspecting the package file listing.

Apparently, there was once an --unlink option available in pkgutil, but as of Lion it is not mentioned in the man page. Perhaps it was removed because it was deemed too dangerous.

Once you've uninstalled the files, you can remove the receipt with:

$ sudo pkgutil --forget the-package-name.pkg
7
  • 1
    I'd recommend using rmdir instead of rm -r; one could also use tac or tail -r to reverse the list of directory names so that they get deleted in the correct order
    – Sam Mason
    Oct 13, 2014 at 13:43
  • 26
    DON'T RUN THE sudo rm -ir PART. The list includes the parent directories! So if the pkg installed something in /usr/... you will remove ALL /usr/ Nov 16, 2014 at 16:56
  • 4
    I have changed the command for deleting directories to use rmdir (which does not delete not-empty-directories) and uses tail -r to list them in better order.
    – brablc
    Nov 17, 2014 at 18:11
  • 1
    ironically, when using pgkutil I found an uninstaller.pl tucked away that I could use. Perfect!
    – cmroanirgo
    Feb 13, 2015 at 2:26
  • 1
    The script uses rmdir to delete directories. And rmdir only deletes empty directories. So unless you want to keep empty directories you do not need to care.
    – brablc
    May 1, 2020 at 17:14
21

Built into the system there is no option to uninstall the files using an uninstaller so you can either make an uninstaller yourself or remove the files manually.

The best method to determine what files have been installed is to get a hold of the original .pkg if possible. If this is not possible you can also use the receipts instead found at /Library/Receipts. Your biggest issue is when you are dealing with a .mpkg which contains multiple .pkg files as you will then have to find all the seperate .pkg files in that folder (thankfully not that difficult when sorted by date).

Once you have the .pkg file (Receipt or the full install file) you can then use a utility to either create the uninstaller or find the files so you can remove them manually:

Uninstaller

Absolute Software InstallEase is a free program that can create uninstallers from existing .pkg files. Make the uninstaller .pkg file (note: You'll need Apple's Developer Tools installed to actually make the .pkg file)

Manually

Using a program such as Pacifist or a QuickLook plugin like Suspicious Package you can view what files are installed and at what location. Using that list you can then manually navigate to those folders and remove the files. I've used this method personally countless times before I discovered InstallEase, but this is still often faster if the install isn't spread out among many locations.

2
  • Thanks, while the regular 5.1 mysql packages left a receipt, the beta 5.4 mysql packages did not. That's slightly odd.
    – dlamblin
    Sep 6, 2009 at 20:34
  • 5
    Wow, if I knew this I never would have installed the .pkg to begin with. y u no Programs and Features OS X? May 1, 2014 at 15:21
10

you can also uninstall .pkg packages with UninstallPKG ( http://www.corecode.at/uninstallpkg/ )

[full disclosure: yes i am the author]

3
  • 3
    It's worth noting it's not free but does include a free trial
    – Ron E
    Mar 23, 2018 at 2:11
  • 1
    Suggesting non-free "solution" for Unix issues is imo a pretty bad philosophy. I mean, we are talking about uninstalling packages...
    – 4wk_
    Sep 19, 2022 at 9:28
  • there is no connection from packages to "Unix". it is a proprietary Apple technology that exists in macOS and does not exist in any other system, Unix, or otherwise. also, SSDReporter has been made free (of charge) a long while ago. Sep 20, 2022 at 10:13
2

I made a shell srcipt

you can try it

https://github.com/iamrToday/pkg-remove

It shows a .gif demo, you can see the source code, just wrap the brablc's command line. You can run it to search infomation , you also can remove apk. It is interactive.

2
  • what does it do? Jun 12, 2018 at 15:09
  • I show a .gif demo, you can see the source code, just wrap the brablc's command line. you can run it to search infomation , you also can remove apk. it is interactive . :)
    – rToday Lin
    Jun 13, 2018 at 15:27
1

You can try the suggestions from this site: http://www.entropy.ch/software/macosx/mysql/remove-old-mysql.html. Also, there's an article regarding this on the Adobe support site; here's the link: http://support.adobe.com/devsup/devsup.nsf/docs/52355.htm.

Also, the apps that usually have a pkg file in the dmg usually also have another pkg that is used for uninstalling. I'm not sure if this is true here, but I wanted to let you know to keep the original dmg file.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .