[Fix] - Install SunOracles proprietary Java JDK or JRE

Wikitechy | 1658 Views | java | 01 Jul 2016


Install Java JDK :

  • We can manually  Download the 32-bit or 64-bit Linux"compressed binary file" - it has a ".tar.gz" file extension.
tar -xvf jdk-8-linux-i586.tar.gz (32-bit)
tar -xvf jdk-8-linux-x64.tar.gz (64-bit)

1.After downloading the file we can extract the JDK 8 package in the ./jdk1.8.0 directory (Check carefully this folder name since Oracle seem to change this occasionally with each update).

2.Now move the JDK 8 package directory to /usr/libby using the following command.

sudo mkdir -p /usr/lib/jvm
sudo mv ./jdk1.8.0 /usr/lib/jvm/

3.After moving the package RUN the following command

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0/bin/javaws" 1
If you use the Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default.
  • If you use the Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default.
  • Suppose you set the higher priority means use the Oracle JDK otherwise set the default.

4.For correct file ownership and the permissions, execute the following command:

sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.8.0

Note :

  • In Java JDK has many more executables So we can similarly install as above. java, javac, javaws are probably the most frequently required.

5.After complete the process “RUN” the following command

sudo update-alternatives --config java
  • And you will see output similar to the one below - choose the number of jdk1.8.0 - for example 3 in this list (unless you have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):
$ sudo update-alternatives --config java
  • There are 3 choices for the alternative java (providing /usr/bin/java).

Selection   Path                                                               Priority             Status


  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071           auto mode

  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071           manual mode

* 2            /usr/lib/jvm/jdk1.7.0/bin/java                            1                 manual mode

  3            /usr/lib/jvm/jdk1.8.0/bin/java                            1                 manual mode

  • Press enter to keep the current choice[*], or type selection number: 3
  • update-alternatives: 
  • use the following path  /usr/lib/jvm/jdk1.8.0/bin/java to provide /usr/bin/java (java) in manual mode
  • Then repeat the above:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

6.If you are a NetBeans users use the following commands:

  • Set the new JDK as default editing the configuration file.
  • And enable the Mozilla Firefox plugin using the following command
32 bit:
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
64 bit:
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
  • We can even link the plugin (libnpjp2.so) to /usr/lib/firefox/plugins/for a system-wide installation (/usr/lib/firefox-addons/plugins from 15.04 onwards).
  • For Ubuntu 13.10, the path to the plugin directory is /usr/lib/firefox/browser/plugins/.

7.Depending on the configuration, we might need to update the apparmor profile for Firefox (or other browsers) in /etc/apparmor.d/abstractions/ubuntu-browsers.d/java in the following path:

# Replace the two lines:
#  /usr/lib/jvm/java-*-sun-1.*/jre/bin/java{,_vm} cx -> browser_java,
#  /usr/lib/jvm/java-*-sun-1.*/jre/lib/*/libnp*.so cx -> browser_java,
# with those (or adapt to your new jdk folder name)
/usr/lib/jvm/jdk*/jre/bin/java{,_vm} cx -> browser_java,
/usr/lib/jvm/jdk*/jre/lib/*/libnp*.so cx -> browser_java,

8.Then restart the apparmo by using the following command

sudo /etc/init.d/apparmor restart
  • Install Oracle Java 7 in Ubuntu or Linux Mint via PPA
  • The Ubuntu package provides Oracle Java JDK 7 (which includes Java JDK, JRE and the Java browser plugin). However, we can't install Oracle JRE - the PPA only provides the full Oracle JDK7 package
  • Ubuntu 13.10 is an older version so no longer supported by Canonical and no security updates are not allowed.
  • If you want to add our PPA and install the latest Oracle Java 7 in Ubuntu following the versions15.04, 14.10, 14.04 and 12.04 or Linux Mint 17.1, 17 and 13, use the commands below:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Note :

  • Some of the firewall / router blocks the redirects required to download the Oracle Java archive. In such cases, download the JDK tar.gz archive manually and place it under the path /var/cache/oracle-jdk7-installer. The"oracle-java7-installer" package will use the local archive instead of trying to download itself.
  • After completing installation, version installed can be checked with the following command:
java -version
  • After complete the process the output will be return the output like this
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
  • If the package installs all the Java binaries, so we can also try "javac -version" which should return "javac 1.7.0_76" and so on (the "_76" part of the version). The current JDK version in the PPA is Oracle Java 7 Update 76 (7u76).
  • If the Java version in use is not 1.7.0 then run the following command:
sudo update-java-alternatives -s java-7-oracle

Update :

  • The installer now requires that we accept the Oracle license before the installation begins. This is only required once. 
  • If for some reason we need the installation to be automated, we can run the following command to automatically accept the Oracle license:
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections

Setting Java environment variables :

  • If you want toset up the Java 7 environment variables automatically,use the following command
sudo apt-get install oracle-java7-set-default
  • If you are already installed oracle-java6-set-default or oracle-java8-set-default, they will be automatically removed when installing oracle-java7-set-default (and the environment variables will be set for Oracle Java 7 instead).
  • Removing Oracle Java 7
  • If you no need to use the Oracle Java (JDK) 7 anymore on your Ubuntu / Linux Mint computer means go back to OpenJDK, and remove the Oracle JDK7 Installer and previous Java (OpenJDK, etc.) version will be used:
sudo apt-get remove oracle-java7-installer

Related Error Tags :

  • How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE?
  • software installation - How to install Oracle Java on Ubuntu 14.04
  • How To Manually Install Oracle Java on a Debian or Ubuntu VPS
  • java - How to install JDK on Ubuntu (Linux)? 
  • How Can I Install Sun/Oracle's Proprietary Java JDK 6/7/8 or JRE 
  • Howto install proprietary Java from Oracle
  • Installing and configuring Java on Linux
  • sun java jdk ubuntu 11.10
  • how to install jdk 8 on ubuntu
  • download jdk 1.7 for ubuntu 64 bit
  • update-java-alternatives
  • install oracle jdk ubuntu
  • unable to locate package oracle-java7-installer
  • ppa:webupd8team/java
  • unable to locate package oracle-java8-installer
  • how to install java in ubuntu 14.04 using terminal