Ubuntu installs the JDK in two ways:
1: Installed via PPA (source) mode.
2: Download the installation package from the official website.
The 1th type is recommended because the JDK upgrade can be facilitated by Apt-get upgrade way
Install using ppa/source 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
Download the JDK package installation directly (this is only about JDK7, the JDK8 principle is exactly the same)
Divided into the following 5 steps
1. Download the JDK on the website
2. Unzip and drop to the specified directory
3. Configure Environment variables
4. Set the system default JDK
5. Test the JDK
1. Download JDK Address: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html
Select the appropriate. gz package to download
2. Unzip and place in the specified directory (take jdk-7u60-linux-x64.gz as an example)
To create a directory:
sudo MKDIR/USR/LIB/JVM
Add compression to the directory:
sudo tar-zxvf jdk-7u60-linux-x64.gz-c/USR/LIB/JVM
3. Modify the Environment variables:
sudo vim ~/.BASHRC
Append the following to the end of the file:
#set Oracle JDK Environment
Export java_home=/usr/lib/jvm/jdk1.7.0_60 # # Note here to replace the directory with your own extracted JDK directory export JRE_HOME=${JAVA_HOME}/JRE export Classpath=.:${java_home}/lib:${jre_home}/lib export Path=${java_home}/bin: $PATH
Make environment variables effective immediately
SOURCE ~/.BASHRC
4. Set the system default JDK version
sudo update-alternatives--install/usr/bin/java java/usr/lib/jvm/jdk1.7.0_60/bin/java sudo Update-alternatives--install/usr/bin/javac Javac/usr/lib/jvm/jdk1.7.0_60/bin/javac sudo Update-alternatives--install/usr/bin/jar jar/usr/lib/jvm/jdk1.7.0_60/bin/jar sudo update-alternatives-- Install/usr/bin/javah javah/usr/lib/jvm/jdk1.7.0_60/bin/javah sudo update-alternatives--install/usr/bin/ JAVAP JAVAP/USR/LIB/JVM/JDK1.7.0_60/BIN/JAVAP 300
Then execute:
sudo update-alternatives--config java
If you install the JDK for the first time, you will be prompted
There is only one alternative in link Group Java (Providing/usr/bin/java):
/usr/lib/jvm/jdk1.7.0_60/bin/java
No, choose the right JDK
5. Test the JDK
Java-version
Java Version "1.7.0_60"
Java (TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot (TM) 64-bit Server VM (build 24.60-b09, Mixed mode)
JDK Installation succeeded
Ubuntu two kinds of installation Jdk7 JDK8 way to complete the introduction
Reference article:
1. http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html2. http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html3.https://www.cnblogs.com/a2211009/p/4265225.html
Ubuntu installs JDK 7/jdk8 in two ways