Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uninstall Ghostscript that comes with MacTex
#!/usr/bin/env bash
# The MacTex website (https://www.tug.org/mactex/uninstalling.html) says it's "difficult"
# to uninstall Ghostscript, as installed by MacTex. Their suggestion is to:
# open the MacTeX-2015 install package and select "Show Files" from the resulting "File" menu of Apple's installer
# and then:
# Find files related to Ghostscript and remove them.
# which is exactly what this script does. It also prints the names of the deleted files, and moves the files to
# the user's Trash instead of actually deleting them. This can help you roll back the effects of the script in
# case something goes wrong.
# Note that this requires write access to the /tmp directory on your computer.
# Example usage:
# You saved "mactex-20150613.pkg" in ~/Downloads and used that to install MacTex.bash uninstall-ghostscript.sh
# This script comes with ABSOLUTELY NO WARRANTY WHATSOEVER. By running it, you agree to take full responsibility
# for anything that happens to your computer as a result.
# At the end of the day, you should have deleted the files:
# /usr/local/bin/dvipdf
# /usr/local/bin/eps2eps
# /usr/local/bin/font2c
# /usr/local/bin/gs-X11
# /usr/local/bin/gs-X11-64Bit
# /usr/local/bin/gs-X11-Yosemite
# /usr/local/bin/gs-noX11
# /usr/local/bin/gs-noX11-64Bit
# /usr/local/bin/gs-noX11-Yosemite
# /usr/local/bin/gsbj
# /usr/local/bin/gsdj
# /usr/local/bin/gsdj500
# /usr/local/bin/gslj
# /usr/local/bin/gslp
# /usr/local/bin/gsnd
# /usr/local/bin/lprsetup.sh
# /usr/local/bin/pdf2dsc
# /usr/local/bin/pdf2ps
# /usr/local/bin/pf2afm
# /usr/local/bin/pfbtopfa
# /usr/local/bin/pphs
# /usr/local/bin/printafm
# /usr/local/bin/ps2ascii
# /usr/local/bin/ps2epsi
# /usr/local/bin/ps2pdf
# /usr/local/bin/ps2pdf12
# /usr/local/bin/ps2pdf13
# /usr/local/bin/ps2pdf14
# /usr/local/bin/ps2pdfwr
# /usr/local/bin/ps2ps
# /usr/local/bin/ps2ps2
# /usr/local/bin/unix-lpr.sh
# /usr/local/bin/wftopfa
# /usr/local/share/man/de/man1/dvipdf.1
# /usr/local/share/man/de/man1/font2c.1
# /usr/local/share/man/de/man1/gsnd.1
# /usr/local/share/man/de/man1/pdf2dsc.1
# /usr/local/share/man/de/man1/pdf2ps.1
# /usr/local/share/man/de/man1/printafm.1
# /usr/local/share/man/de/man1/ps2ascii.1
# /usr/local/share/man/de/man1/ps2pdf.1
# /usr/local/share/man/de/man1/ps2ps.1
# /usr/local/share/man/de/man1/wftopfa.1
# /usr/local/share/man/man1/dvipdf.1
# /usr/local/share/man/man1/font2c.1
# /usr/local/share/man/man1/gs.1
# /usr/local/share/man/man1/gslp.1
# /usr/local/share/man/man1/gsnd.1
# /usr/local/share/man/man1/pdf2dsc.1
# /usr/local/share/man/man1/pdf2ps.1
# /usr/local/share/man/man1/pf2afm.1
# /usr/local/share/man/man1/pfbtopfa.1
# /usr/local/share/man/man1/printafm.1
# /usr/local/share/man/man1/ps2ascii.1
# /usr/local/share/man/man1/ps2epsi.1
# /usr/local/share/man/man1/ps2pdf.1
# /usr/local/share/man/man1/ps2pdfwr.1
# /usr/local/share/man/man1/ps2ps.1
# /usr/local/share/man/man1/wftopfa.1
#
# and the directory:
# /usr/local/share/ghostscript/
uninstall_ghostscript () {
bom_usr_local=$(pkgutil --bom $1 | fgrep local.pkg)
files=( $(lsbom -s -f $bom_usr_local | fgrep -v ghostscript | sed 's_^\._/usr/local_') )
command mv -i $files ~/.Trash
command mv -i /usr/local/share/ghostscript ~/.Trash
}
uninstall_ghostscript $1
@meling

This comment has been minimized.

Copy link

@meling meling commented Apr 30, 2020

It is not so clear what the argument to this script should be. If run without an argument I get:

pkgutil: option `--bom' requires an argument

Does it need the mactex.pkg file that I already deleted?

@gwerbin

This comment has been minimized.

Copy link
Owner Author

@gwerbin gwerbin commented May 20, 2020

This was a long time ago, but yes I believe so, @meling. You should be able to re-download the PKG file at least. This script basically just extracts the list of installed files from the PKG and moves them to the trash one by one (in a somewhat insecure manner, I might add).

I haven't tested this at all, but the following code would be considered better practice:

uninstall_ghostscript () {
  bom_usr_local=$(pkgutil --bom $1 | grep -F local.pkg)
  lsbom -s -f $bom_usr_local | grep -F -v ghostscript | sed 's_^\._/usr/local_' | while read filename; do 
    command mv - "$filename" ~/.Trash
  done
  command mv -v /usr/local/share/ghostscript ~/.Trash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment