Skip to content

Instantly share code, notes, and snippets.

@rtrouton
Last active December 18, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrouton/5852198 to your computer and use it in GitHub Desktop.
Save rtrouton/5852198 to your computer and use it in GitHub Desktop.
Using the JAVA_INSTALL_ON_DEMAND environment variable to force Macs running 10.7.x or 10.8.x to reinstall the latest Java update.
#!/bin/bash
# Original version of this script posted by
# Michael Kuron <michael-lists@PHYSCIP.UNI-STUTTGART.DE>
# Posted to the MacEnterprise list on June 22, 2013:
# http://tinyurl.com/m8fp4ou
#
# This script works on Mac OS X 10.7.0 and higher
#
# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
if [[ ${osvers} -ge 7 ]]; then
# Checks the current Java version and displays the results
java -version
# Set the JAVA_INSTALL_ON_DEMAND
# environment variable. This variable
# overrides the install check and forces
# the softwareupdate tool to install Apple's
# latest Java 6 update
export JAVA_INSTALL_ON_DEMAND=1
# Uses the softwareupdate tool to check
# for and get the name of the latest Apple
# Java update for 10.7.x and 10.8.x
pkgname=$(softwareupdate --list | grep '*' | grep -i java | awk '{print $2}')
# Installs the latest available Apple
# Java update for 10.7.x and 10.8.x
softwareupdate --install $pkgname
# Checks the current Java version and displays the results
java -version
else
echo "Not supported on this version of Mac OS X"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment