También puede instalar openjdk usando este script bash, que obtiene OpenJDK de Zulu, un proveedor comercial que crea y lanza OpenJDK gratis aquí
Puede instalarlo manualmente desde el enlace anterior o usar este script. ¡Tu llamada!
openjdk_install_on_mac.sh
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; PATH="$DIR:$PATH"
ME=$(basename $0)
show_help()
{
NEW_HOME9="$JDK_HOME/openjdk9"
IT=$(cat <<EOF
Installs the latest OpenJDK on your mac, version 8 by default
usage: sudo $ME {OPENJDK FOLDER NAME} {JDK_VERSION_TO_DOWNLOAD}
e.g.
sudo $ME openjdk8 # installs openjdk 8 to $NEW_HOME on your machine.
sudo $ME openjdk9 9 # installs openjdk 9 to $NEW_HOME9 on your machine.
EOF
)
echo "$IT"
exit
}
if [ "$1" == "help" ]
then
show_help
fi
# Ensure running as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
echo "To do this, run 'sudo $ME' instead."
exit 1
fi
JDK_HOME="/Library/Java/JavaVirtualMachines"
JDK_VERSION=${2:-8}
JDK_NAME=${1:-openjdk$JDK_VERSION}
NEW_HOME="$JDK_HOME/$JDK_NAME"
# Ensure no jdk already in target folder
if [ -d "$NEW_HOME" ]; then
echo "A JDK is already installed at $NEW_HOME"
echo "Please supply a unique name and try again!"
exit 1
fi
echo
echo "About to install openjdk to $NEW_HOME"
read -n1 -r -p "Press any key to continue, or Ctrl-C to abort"
echo
url_extract()
{
tr '"' '\n' | tr "'" '\n' | grep -e ^https:// -e ^http:// -e^// | sort | uniq
}
FILE=/tmp/__jdk_info
curl -s -o $FILE https://www.azul.com/downloads/zulu/zulu-mac/
NEWEST_OPENJDK=$(cat "$FILE" | url_extract | grep "zulu$JDK_VERSION" | grep tar.gz | grep -v pdf | tail -n1)
rm $FILE
echo "About to download latest version of JDK from"
echo "$NEWEST_OPENJDK"
echo "..."
sleep 0.5
FILE=/tmp/__openjdk_download.tar.gz
echo "$NEWEST_OPENJDK"
curl -o "$FILE" "$NEWEST_OPENJDK"
DIR=/tmp/__openjdk
mkdir -p "$DIR"
tar zxvf "$FILE" -C "$DIR"
rm $FILE
mv "$DIR/"* "$NEW_HOME"
rm -fr "$DIR"
echo
echo "Installation Complete!"
echo
echo "OpenJDK now available at $NEW_HOME"