Two ways to install JDK in Ubuntu

Source: Internet
Author: User

1: Installed through the PPA (source) mode.

2: Download the installation package through the official website.

1th is recommended here because the JDK upgrade can be easily obtained by Apt-get upgrade method. install using the ppa/source method Add PPA

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update
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 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 set the system default JDK using the tar.gz package you download

JDk7:
sudo update-java-alternatives-s java-7-oracle
JDK8:
sudo update-java-alternatives-s Java-8-oracle

If the installation of the JDK7, and installed the JDK8, to achieve 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
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

     2. Extract, put to the specified directory

     3. Configure environment variable

     4. Set system default JDK

  5. Test jdk
  '

# # website Download jdk
     Address: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html
Select the corresponding. gz package Download

# # decompression, Put 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
"' Modify environment variables:

The sudo vim ~/.bashrc
file appends the following:

#set Oracle JDK Environment
Export java_home=/usr/lib/jvm/jdk1.7.0_60  # # Here to note the directory to be replaced by their 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 variable effective immediately

 source ~/.BASHRC
 '
# Set 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 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
"'

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.