1. Add PPA
sudo add-apt-repository ppa:webupd8team/javasudo apt-get update
2. Installing Oracle-java-installer
Jdk7
sudo apt-get install Oracle-java7-installer
Jdk8
sudo apt-get install Oracle-java8-installer
The installer will prompt you to agree to Oracle's terms of service, select OK
Then select Yes to
If you're lazy, don't want to manually click on it yourself. You can also add the following command, by default, agree to the terms:
JDK7 Default Selection Terms
echo oracle-java7-installer Shared/accepted-oracle-license-v1-1 Select True | Sudo/usr/bin/debconf-set-selections
JDK8 Default Selection Terms
echo oracle-java8-installer Shared/accepted-oracle-license-v1-1 Select True | Sudo/usr/bin/debconf-set-selections
Next will be waiting (depending on the speed of the individual)
If you cause installer to download slowly due to firewalls or other reasons, you can interrupt the operation. Then download the tar.gz package for the corresponding JDK, and put it in:
/var/cache/oracle-jdk7-installer (JDK7)
/var/cache/oracle-jdk8-installer (JDK8)
Below, and then install the installer once. Installer will use the TAR.GZ package you downloaded by default
3. Set the system default JDK
JDk7
sudo update-java-alternatives-s java-7-oracle
JDK8
sudo update-java-alternatives-s java-8-oracle
If the JDK7 is installed and the JDK8 is installed, to switch between the two, you can:
JDK8 Switch to Jdk7
sudo update-java-alternatives-s java-7-oracle
JDK7 Switch to Jdk8
sudo update-java-alternatives-s java-8-oracle
4. Test whether the JDK was installed successfully:
Java-versionjavac-version
Linux installs JDK using ppa/source mode