1: Install through ppa (source).
2: Download the installation package from the official website.
The first option is recommended here, because you can easily get the jdk upgrade through apt-get upgrade
sudo add-apt-repository ppa:webupd8team/javasudo apt-get update
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
If you are lazy and don’t want to click manually. You can also add the following command and agree to the terms by default:
JDK8 default selection terms
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
The next step will be waiting (depending on personal network speed)
If the download speed of the installer is very slow due to firewall or other reasons, you can interrupt the operation. Then download The corresponding jdk tar.gz package is placed under:
/var/cache/oracle-jdk8-installer (jdk8)
, and then install the installer once. The installer will use the tar.gz package you downloaded by default
JDK8
sudo update-java-alternatives -s java-8-oracle
If jdk7 and jdk8 are installed simultaneously, to switch between the two, you can:
Switch jdk8 to jdk7
sudo update-java-alternatives -s java-7-oracle
Switch jdk7 to jdk8
sudo update-java-alternatives -s java-8-oracle
4. Test whether jdk is installed successfully:
java -version javac -version
It is divided into the following 5 steps
1. Download JDK from the official website
2. Unzip it and put it in the specified directory
3 .Configure environment variables
4. Set the system default JDK
5. Test jdk
Select the corresponding .gz Package download
Create directory:
sudo mkdir /usr/lib/jvm
Add compression to this directory:
sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm
sudo vim ~/.bashrc
Append the following content at the end of the file:
#set oracle jdk environment export JAVA_HOME=/usr/lib/jvm/
Make the environment variables take effect immediately
source ~/.bashrc
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_60/bin/javac 300 sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_60/bin/jar 300 sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.7.0_60/bin/javah 300 sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0_60/bin/javap 300
Then Execution:
sudo update-alternatives --config java
If it is the first time to install jdk, there will be the following prompt
There is only one alternative in link group java (providing /usr/bin/ java):
/usr/lib/jvm/jdk1.7.0_60/bin/java
Otherwise, choose the appropriate 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)
1. 2.
The above is the detailed content of Two ways to install JDK8 on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!