Ubuntu installs JDK 7/jdk8 in two ways

Source: Internet
Author: User

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

Install Oracle-java7-installer

Jdk8

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-sudo/usr/bin/ Debconf-set-selections

JDK8 Default Selection Terms

echo Oracle-java8-installer shared/accepted-oracle-license-v1-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:

Mkdir/usr/lib/jvm

Add compression to the directory:

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 # # Here are the directories to be replaced with their own extracted JDK directory export jre_home=${java_home}/ JRE export classpath=.:${java_home}/lib:${jre_home}/

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/java300sudo 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                

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.html

Ubuntu installs JDK 7/jdk8 in two ways

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.