Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active March 31, 2024 17:59
Show Gist options
  • Star 75 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save githubutilities/b5318d08a4b970d104f1 to your computer and use it in GitHub Desktop.
Save githubutilities/b5318d08a4b970d104f1 to your computer and use it in GitHub Desktop.
Uninstall pkg manually in OS X

Mac Uninstall pkg Manually

  • using pkgutil
# list all your installed packages
pkgutil --pkgs

# show your package info
pkgutil --pkg-info <your-package-id>

# list your package files
pkgutil --files <your-package-id>

# change to the directory which your package is installed into
cd /
# remote files
pkgutil --only-files --files <your-package-id> | tr '\n' '\0' | xargs -n 1 -0 sudo rm -if
# remote directories
pkgutil --only-dirs --files <your-package-id> | tail -r | tr '\n' '\0' | xargs -n 1 -0 sudo rmdir

Reference

@huttarl
Copy link

huttarl commented Feb 8, 2017

How does rm -if make sense? This rm man page says that -i means "prompt before every removal", but -f means "never prompt"! Moreover, prompting is useless since stdin is coming from a /dev/null thanks to xargs. Right?

Note also that pkgutil --files can output names of important directories shared with other programs, e.g. usr. That's OK if you use rmdir as this script does, because it won't remove empty directories. But if you modify the commands, e.g. to use rm -r, be very careful.

@scottcmarks
Copy link

scottcmarks commented Jun 17, 2017

You might want to finally clean up with

sudo pkgutil --forget <your-package-id>

@Motti-Shneor
Copy link

Hi, is it a typo in your comments "# remote files" (that should be "# remove files", same for directories?

If it is not a mistake - why the word "remote" and what does it mean in this context?

@uhlhosting
Copy link

rm -if => rm -rf
rmdir => rm -rf

Much simpler.

@fejese
Copy link

fejese commented Jun 17, 2023

@uhlhosting

rm -if => rm -rf
rmdir => rm -rf

Much simpler.

only if you potentially want to brick your machine. pkg files can include files to be installed even to /System in which case /System will be listed and you'd try to rm -rf that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment