Java install

Install Java 6

1. Download and extract Java

tmp_dir="/root/tmp/java" ; mkdir -p "${tmp_dir}" && cd "${tmp_dir}"

Start here and get url for something like jdk-6u45-linux-x64.bin

cookie='Cookie: oraclelicensejdk-6u45-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com' url='http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin' filename='jdk-6u45-linux-x64.bin' wget -c --no-check-certificate --header="${cookie}" "${url}" -O "${filename}" chmod u+x "${filename}" ./"${filename}"

2. Install Java to /opt/oracle

dest="/opt/oracle" mkdir -p "${dest}" mv jdk1.6.0_45 "${dest}" cd "${dest}" && ln -s jdk1.6.0_45 java alternatives --install /usr/bin/java java "${dest}"/java/bin/java 1

    1. Confirm Java is working

    2. alternatives --config java

There is 1 program that provides 'java'. Selection Command ----------------------------------------------- *+ 1 /opt/oracle/jdk1.6.0_39/bin/java Enter to keep the current selection[+], or type selection number:

  • which java

    • Confirm "/usr/bin/java"

  • java -version

java -version java version "1.6.0_39" Java(TM) SE Runtime Environment (build 1.6.0_39-b04) Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)

4. Set the JAVA_HOME

  • update-alternatives --display java

# update-alternatives --display java java - status is auto. link currently points to /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java - priority 170025 ...

    • vim /root/.bash_profile

      • /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/

Install Java 7

1. Download and extract Java

Start here to get your download link and use this cookie workaround.

version="7u15" app_dst="/opt/oracle" ; mkdir -p ${app_dst} ; tmp_dir="/root/tmp/java" ; mkdir -p ${tmp_dir} ; cd ${tmp_dir} # 7u21 cookie='Cookie: oraclelicensejdk-7u21-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com' url='http://download.oracle.com/otn-pub/java/jdk/7u21-b11/jdk-7u21-linux-x64.tar.gz' filename='jdk-7u21-linux-x64.tar.gz' wget -c --no-check-certificate --header="${cookie}" "${url}" -O "${filename}" tar -xvzf "${filename}" dir='jdk1.7.0_21'

2. Install Java

mv "${dir}" ${app_dst} cd ${app_dst} ln -s "${dir}" java rm -rf ${tmp_dir} alternatives --install /usr/bin/java java /opt/oracle/jdk1*/bin/java 1 alternatives --config java # Confirm: 1 /opt/oracle/jdk1.7.0_15/bin/java which java # Confirm "/usr/bin/java" java -version

2. Configure Java Environment

  • vim /etc/profile.d/java.sh

JAVA_HOME="/usr/java/jdk1.7.0_15" PATH="${PATH}:${JAVA_HOME}/jre/bin" export PATH JAVA_HOME LD_LIBRARY_PATH

  • chmod 644 /etc/profile.d/java.sh

vim /etc/profile # Add the following section at the end # # Installed Java 7 - JGS # export PATH=$PATH:/usr/java/jdk1.7.0_15/bin export JAVA_HOME=/usr/java/jdk1.7.0_15

    • vim /etc/environment

        • Add the following line

JAVA_HOME=/usr/java/jdk1.7.0_15

3. Confirm Java is working

  • java -version

# java -version java version "1.7.0_15" Java(TM) SE Runtime Environment (build 1.7.0_15-b03) Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

[Edit]