Puoi anche installare openjdk usando questo script bash, che ottiene OpenJDK da Zulu, un venditore commerciale che costruisce e rilascia OpenJDK gratuito qui
Puoi semplicemente installarlo manualmente dal link sopra, o usare questo script. La tua chiamata!
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"