openjdk-11.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_OpenJDK11() {
  11. if [ "${Family}" == 'rhel' ]; then
  12. yum -y install java-11-openjdk-devel
  13. JAVA_HOME=/usr/lib/jvm/java-11-openjdk
  14. elif [ "${Family}" == 'debian' ]; then
  15. apt-get --no-install-recommends -y install openjdk-11-jdk
  16. JAVA_HOME=/usr/lib/jvm/java-11-openjdk-${SYS_ARCH}
  17. elif [ "${Family}" == 'ubuntu' ]; then
  18. if [[ "${Ubuntu_ver}" =~ ^16$ ]]; then
  19. cat ${oneinstack_dir}/src/adoptium.key | sudo apt-key add -
  20. apt-add-repository --yes https://mirrors.tuna.tsinghua.edu.cn/Adoptium/deb
  21. apt -y update
  22. apt-get --no-install-recommends -y install temurin-11-jdk
  23. JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-${SYS_ARCH}
  24. else
  25. apt-get --no-install-recommends -y install openjdk-11-jdk
  26. JAVA_HOME=/usr/lib/jvm/java-11-openjdk-${SYS_ARCH}
  27. fi
  28. fi
  29. if [ -e "${JAVA_HOME}/bin/java" ]; then
  30. cat > /etc/profile.d/openjdk.sh << EOF
  31. export JAVA_HOME=${JAVA_HOME}
  32. export CLASSPATH=\$JAVA_HOME/lib/tools.jar:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib
  33. EOF
  34. . /etc/profile.d/openjdk.sh
  35. echo "${CSUCCESS}OpenJDK11 installed successfully! ${CEND}"
  36. else
  37. echo "${CFAILURE}OpenJDK11 install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  38. kill -9 $$; exit 1;
  39. fi
  40. }