Home  >  Article  >  Java  >  Two ways to install JDK8 on Ubuntu

Two ways to install JDK8 on Ubuntu

巴扎黑
巴扎黑Original
2017-06-23 16:28:412454browse

There are two ways to install jdk on ubuntu:

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

Use ppa/source method to install

1. Add ppa

sudo add-apt-repository ppa:webupd8team/javasudo apt-get update

2. Install oracle-java-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

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

3. Set the system default jdk

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

Directly download the jdk compressed package and install it (here we only introduce jdk7 and jdk8 The principle is completely the same)

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

1. Download JDK from the official website   

Address:

Select the corresponding .gz Package download

2. Unzip and place it in the specified directory (take jdk-7u60-linux-x64.gz as an example)

Create directory:

sudo mkdir /usr/lib/jvm

Add compression to this directory:

 sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm

3. Modify the environment variables:

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

4. Set the system default jdk version

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

##5 .Test 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 successful

ubuntu Two ways to install jdk7 jdk8 have been introduced

Reference article:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn