Install Sun / Oracle Java JDK under Ubuntu

  • warning: Illegal string offset 'files' in /data/web/1/000/027/003/273448/htdocs/panticz.de/modules/upload/upload.module on line 281.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.
  • warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/web/1/000/027/003/273448/htdocs/panticz.de/includes/unicode.inc on line 349.

wget -q --no-check-certificate -O - | bash -

#!/bin/bash

# ensure that this script is run by root
if [ $(id -u) -ne 0 ]; then
sudo $0
exit
fi

# install debconf
apt-get install -y debconf-utils

# create answer file
debconf-set-selections <<\EOF
oracle-java8-installer shared/accepted-oracle-license-v1-1 select true
EOF

# ensure that add-apt-repository is installed
. /etc/os-release
if [ "${ID}" == "debian" ] && [ "${VERSION_ID}" == "7" ] ; then
# Debian Wheezy
apt-get install -y python-software-properties
else
# Ubuntu and Debian Jessie
apt-get install -y software-properties-common
fi

# add repository
add-apt-repository -y ppa:webupd8team/java

# fix distribution name on Debian
for FILE in $(find /etc/apt/sources.list.d/ -name "*webupd8team*.list"); do
sed -i 's|wheezy|precise|g;s|jessie|trusty|g' ${FILE}
done

# update repository
apt-get update -qq

# bypass the apt-cacher-ng proxy
echo 'Acquire::HTTP::Proxy::download.oracle.com "DIRECT";' > /etc/apt/apt.conf.d/99_oracle

# install
apt-get install -y oracle-java8-installer

# set Java environment variables
apt-get install -y oracle-java8-set-default

# set java 8 as default java version
update-java-alternatives -s java-8-oracle

# move java desktop symbols
[ -f /usr/share/applications/JB-mission-control-jdk8.desktop ] && sed -i 's|Categories=Development;Java;|Categories=Application;Network;|g' /usr/share/applications/JB-mission-control-jdk8.desktop

Java 10

Install JDK under Debian 7 (minimal)
echo "deb precise main" > /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
echo 'Acquire::HTTP::Proxy::download.oracle.com "DIRECT";' > /etc/apt/apt.conf.d/99_oracle
apt-get update
echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
apt-get install -y oracle-java7-installer
apt-get install -y oracle-java7-set-default

Download JDK manually
# v7
URL=http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.tar.gz
# v8
URL=http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz
# download
wget --continue --no-check-certificate --header "Cookie: oraclelicense=a" ${URL} -O /tmp/${URL##*/}

#

# fix repo key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886

OPTIONAL: Uninstall OpenJDK
sudo apt-get remove -y openjdk-7-jre-headless

Display your current java version
java -version

# configure systemwide profile
echo "export JAVA_HOME=/opt/jvm/current" > /etc/profile.d/java.sh

Links

- HowTo, install Java under Ubuntu and Debian
- webupd8team Java repository