Setting Up Oracle JDK On GNU/Linux

Table of Contents

Java SE is an abbreviation for Java Platform, Standard Edition, and JDK is an abbreviation for Java SE Development Kit. JDK provides running environment for Java applications. This article documents how to set up Oracle JDK on GNU/Linux, then implement the entire process through Shell script.

Attention: Oracle will not post further updates of Java SE 8 to its public download sites for commercial use after January 2019.

Customers who need continued access to critical bug fixes and security fixes as well as general maintenance for Java SE 8 or previous versions can get long term support through Oracle Java SE Advanced, Oracle Java SE Advanced Desktop, or Oracle Java SE Suite. For more information, and details on how to receive longer term support for Oracle JDK 8, please see the Oracle Java SE Support Roadmap. – http://www.oracle.com/technetwork/java/javase/overview/index.html

Shell Script

The entire installation and configuration process has been implemented through a shell script, the code is hosted on GitLab, usage info

1
2
3
4
# curl -fsL / wget -qO-

# if need help info, specify '-h'
curl -fsL https://gitlab.com/MaxdSre/axd-ShellScript/raw/master/assets/software/OracleSEJDK.sh | sudo bash -s --

Support Life Cycle

The support life cycly of per JDK release version is list on official page Oracle Java SE Support Roadmap

Java SE Public Updates

Release GA Date End of Public Updates Notification End of Public Updates
8 Mar 2014 Sep 2017 January 2019 and December 2020
9 Sep 2017 Sep 2017 Mar 2018
10 (18.3) Mar 2018 Mar 2018 Sep 2018
11(18.9 LTS) Sep 2018

Java SE Support Roadmap

Release GA Date Premier Support Until Extended Support Until Sustaining Support
6 Dec 2006 Dec 2015 Dec 2018 Indefinite
7 Jul 2011 Jul 2019 Jul 2022 Indefinite
8 Mar 2014 Mar 2022 Mar 2025 Indefinite
9 (non-LTS) Sep 2017 Mar 2018 Not Available Indefinite
10 (18.3^) (non-LTS) Mar 2018 Sep 2018 Not Available Indefinite
11 (18.9 LTS) Sep 2018 Sep 2023 Sep 2026 Indefinite

Downloading

Official download page Java SE Downloads

If you wanna download JDK from Oracle official site, you must accept is license Oracle Binary Code License Agreement for Java SE firstly. After checking Accept License Agreement, the page will show the following info

Thank you for accepting the Oracle Binary Code License Agreement for Java SE; you may now download this software.

How do I download jdk package directly from official site in command line or shell script?

Reference

Oracle makes sure user has agree the license via directive oraclelicense which is setted in cookie. The complete parameter is oraclelicense=accept-securebackup-cookie.

Downloading in silent mode

1
2
3
4
5
# curl
curl -fsL -O -H "Cookie: oraclelicense=accept-securebackup-cookie" "${pack_download_link}"

# wget
wget -qO- -O "${pack_download_link##*/}" --header="Cookie: oraclelicense=accept-securebackup-cookie" "${pack_download_link}"

Installation

Suffix of package is .tar.gz, use the following command to extract its contents to target directory

1
2
3
4
pack_path='~/Downloads/jdk-8u172-linux-x64.tar.gz'
installation_dir='/opt/OracleJDK'

tar xf "${source_pack_path}" -C "${installation_dir}" --strip-components=1 2> /dev/null

Configuration

File tree

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
┌─[[email protected]][/opt/OracleJDK]
└──╼ $tree -L 1
.
├── bin
├── COPYRIGHT
├── include
├── javafx-src.zip
├── jre
├── lib
├── LICENSE
├── man
├── README.html
├── release
├── src.zip
├── THIRDPARTYLICENSEREADME-JAVAFX.txt
└── THIRDPARTYLICENSEREADME.txt

5 directories, 8 files
┌─[[email protected]][/opt/OracleJDK]
└──╼ $

$PATH

Execution files are listed in directory bin/, you need to add this path into environment parameter $PATH.

But personal advice is put this directive under directory /etc/profile.d/, here assume the file is called oracle_se_jdk.sh.

1
2
3
jdk_execute_path='/etc/profile.d/oracle_se_jdk.sh'

echo "export PATH=${installation_dir}/bin:\$PATH" >> "${jdk_execute_path}"

Aalternatives

If your system has more than one JDK version, you can use alternatives or update-alternatives to set default execution path for java.

shell code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
funcAlternativeModeConfiguration(){
    local jdkcommand="${1:-}"
    local jdkaction="${2:-'install'}"
    local jdkdir="${3:-"${installation_dir}"}"

    if [[ -n "${jdkdir}" && -n "${alternative_command}" ]]; then
        local jdkcommand_path
        jdkcommand_path="${jdkdir}/bin/${jdkcommand}"

        case "${jdkaction}" in
            install )
                if [[ -s "${jdkcommand_path}" ]]; then
                    ${alternative_command} --install /usr/bin/"${jdkcommand}" "${jdkcommand}" "${jdkcommand_path}" 99 &> /dev/null
                    ${alternative_command} --set "${jdkcommand}" "${jdkcommand_path}" &> /dev/null
                fi
                ;;
            remove|* )
                if [[ -s "${jdkcommand_path}" ]]; then
                    ${alternative_command} --remove "${jdkcommand}" "${jdkcommand_path}" &> /dev/null
                fi
                ;;
        esac
    fi
}

alternative_command='alternatives'
# alternative_command='update-alternatives'

funcAlternativeModeConfiguration 'java' 'remove'
# funcAlternativeModeConfiguration 'javac' 'remove'
# funcAlternativeModeConfiguration 'jar' 'remove'

Testing

Demostration example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
┌─[[email protected]][~]
└──╼ $which java
/usr/bin/java
┌─[[email protected]][~]
└──╼ $java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
┌─[[email protected]][~]
└──╼ $update-alternatives --display java
java - manual mode
  link best version is /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
  link currently points to /opt/OracleSEJDK/bin/java
  link java is /usr/bin/java
  slave java.1.gz is /usr/share/man/man1/java.1.gz
/opt/OracleSEJDK/bin/java - priority 99
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1081
  slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
┌─[[email protected]][~]
└──╼ $

Reference

Change Logs

  • 2018.04.19 16:48 Wed America/Boston
    • first draft
  • 2018.05.14 09:08 Mon America/Boston
    • add reference
  • 2018.11.29 10:28 Thu America/Boston
    • update release version
Show Disqus Comments