Uninstall Java Mountain Lion [duplicate]

Solution 1:

Apple provides an automatic Java installer but no uninstaller so you can't remove Java once you've installed it without using an at-your-own-risk approach.

That being said this is how to get rid of java from a terminal session and a using a text editor:

sudo rm -rf /System/Library/Java/JavaVirtualMachines/
sudo rm -rf /Library/Java/JavaVirtualMachines/*.jdk
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefpane
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaEssentials.bom
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaEssentials.plist
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaForMacOSX107.bom
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaForMacOSX107.plist
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaMDNS.bom
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaMDNS.plist
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaSecurity.bom
sudo rm -rf /private/var/db/receipts/com.apple.pkg.JavaSecurity.plist

At this point you need to edit the installation history to delete evidence you installed Java. I suggest backing up the file first. If you prefer a different text editor feel free to use it but do not use a word processor that puts formatting codes in the text file.

sudo cp /Library/Receipts/InstallHistory.plist ~/Desktop
sudo emacs /Library/Receipts/InstallHistory.plist

Search for entries that look like:

    <dict>
            <key>date</key>
            <date>2011-09-16T22:22:10Z</date>
            <key>displayName</key>
            <string>Java for Mac OS X 10.6 Update 5</string>
            <key>displayVersion</key>
            <string>1.0</string>
            <key>packageIdentifiers</key>
            <array>
                    <string>com.apple.pkg.JavaForMacOSX10.6Update5</string>
            </array>
            <key>processName</key>
            <string>Software Update</string>
    </dict>

also

    <dict>
            <key>date</key>
            <date>2013-01-15T11:42:35Z</date>
            <key>displayName</key>
            <string>Java for OS X 2012-006</string>
            <key>displayVersion</key>
            <string>1.0</string>
            <key>packageIdentifiers</key>
            <array>
                    <string>com.apple.pkg.JavaEssentials</string>
                    <string>com.apple.pkg.JavaForMacOSX107</string>
                    <string>com.apple.pkg.JavaSecurity</string>
                    <string>com.apple.pkg.JavaMDNS</string>
            </array>
            <key>processName</key>
            <string>Software Update</string>
    </dict>

and delete them. You may wish to check your work using diff:

diff -u ~/Desktop/InstallHistory.plist /Library/Receipts/InstallHistory.plist | less

or some other file comparison tool.

You can test that java is gone by running:

java -version

You should see a pop up asking to install Java again.