Ubuntu Install Oracle Java JDK

Source: Internet
Author: User


Ubuntu installs JDK in two ways:

1: Installed through the PPA (source) mode.

2: Download the installation package through the official website.

1th is recommended here because you can easily get the JDK upgrade using the Apt-get upgrade method ppa/Source installation 1. Add PPA

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update
2. Install 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 and select OK

Then select Yes

If you are lazy, do not want to manually click on your own. You can also add the following command to the default consent clause:

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 are slow to download the installer because of a firewall or some other reason, you can interrupt the operation. then download the corresponding JDK tar.gz package, put in:

/var/cache/oracle-jdk7-installer (JDK7)

/var/cache/oracle-jdk8-installer (JDK8)

Below, and then install the installer once. Installer will default to use the tar.gz package you downloaded 3. Set 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 enable the 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-version

javac-version
Download the JDK compression package directly (the JDK7 is only introduced here, the JDK8 principle is exactly the same)

Divided into the following 5 steps

1. Download JDK on website

2. Unzip, put in the specified directory

3. Configure Environment variables

4. Set the system default JDK

5. Test JDK 1. Download JDK on website

     地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html

Select the appropriate. gz package download 2. Unzip, and place in the specified directory (for example, jdk-7u60-linux-x64.gz)

To create a directory:

sudo MKDIR/USR/LIB/JVM

To compress to this directory:

sudo tar-zxvf jdk-7u60-linux-x64.gz-c/USR/LIB/JVM
3. Modify 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 to note the directory to be replaced by its 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 have the following tips

There is only one alternative in link Group Java (Providing/usr/bin/java):
/usr/lib/jvm/jdk1.7.0_60/bin/java

No, select 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 installed successfully

See http://www.cnblogs.com/a2211009/p/4265225.html

Related Article

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.