Home > Java > javaTutorial > body text

Two ways to install JDK8 on Ubuntu

巴扎黑
Release: 2017-06-23 16:28:41
Original
2471 people have browsed it

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
Copy after login

2. Install oracle-java-installer

jdk8

sudo apt-get install oracle-java8-installer
Copy after login

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
Copy after login

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
Copy after login
Copy after login

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
Copy after login

Switch jdk7 to jdk8

sudo update-java-alternatives -s java-8-oracle
Copy after login
Copy after login

4. Test whether jdk is installed successfully:

java -version

javac -version
Copy after login

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
Copy after login

Add compression to this directory:

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

3. Modify the environment variables:

sudo vim ~/.bashrc
Copy after login

Append the following content at the end of the file:

#set oracle jdk environment
export JAVA_HOME=/usr/lib/jvm/
Copy after login

Make the environment variables take effect immediately

 source ~/.bashrc
Copy after login

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
Copy after login

Then Execution:

sudo update-alternatives --config java
Copy after login

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"
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template