Install JDK under Ubuntu

Source: Internet
Author: User

安装环境:ubuntu14.04。JDK不只Oracle一家,但出于习惯问题,我还是选择安装Oracle的JDK。安装方法有两种,一种是通过ppa安装自动配置环境,另一种是下载压缩包解压后自己配置环境。第一种方法比较省事,只是有一个前提:必须上网。第二种方法稍微麻烦一些,有些像在Windows的安装配置。

1 Installing using the PPA source method

1.1 Adding PPA
sudo add-apt-repository Ppa:webupd8team/java
sudo apt-get update

1.2 Installing Oracle-java-installer
sudo apt-get install Oracle-java8-installer
The installer will prompt you to agree to Oracle's terms of service, select OK, and then select Yes (note that you want to use the keyboard.) )。

1.3 Setting the system default JDK
sudo update-java-alternatives-s java-8-oracle

1.4 Test the JDK to see if the installation was successful:
Java-version
Javac-version
This method automatically configures the environment.

2 Direct download JDK package installation

2.1 Website Download JDK
The address is not listed, I believe you can find it. When open, select the appropriate. gz package to download

2.2 Unzip, put in the specified directory (take jdk-8u151-linux-x64.tar.gz as an example)
Create a Directory
sudo MKDIR/USR/LIB/JVM
Unzip to this directory
sudo tar-zxvf jdk-8u151-linux-x64.tar.gz-c/USR/LIB/JVM

2.3 Modifying environment variables
sudo vim ~/.BASHRC
Append the following to the end of the file

#set oracle jdk environmentexport JAVA_HOME=/usr/lib/jvm/jdk1.8.0_151  ## 这里要注意目录要换成自己解压的jdk 目录export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATH

Make environment variables effective immediately
SOURCE ~/.BASHRC

2.4 Setting the system default JDK version

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_151/bin/java 300sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_151/bin/javac 300sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.8.0_151/bin/jar 300sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.8.0_151/bin/javah 300sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.8.0_151/bin/javap 300

And 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.8.0_151/bin/java
No, choose the right JDK

2.5 Testing the JDK
Input command: java-version
The results appear as follows:
Java Version "1.8.0_151"
Java (TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot (TM) 64-bit Server VM (build 24.60-b09, Mixed mode)
Input command: javac-version
The results appear as follows:
Javac 1.8.0_151
At this point, the JDK installation succeeded

Install JDK under Ubuntu

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.