Ubuntu16.04 install java JDK8

There are two versions of Java JDK in the Linux system, an open source version Openjdk, and an official version of oracle jdk. The oracle JDK can be installed by adding the ppa source command line or downloading the jdk compressed package from the official website. Here are the steps of these three installation methods. It is recommended to use the first method directly , which is simple and quick.
 

Method 1: Install the open source version of openjdk

1. Update the package list:

$ sudo apt-get update

2. Install openjdk-8-jdk:

$ sudo apt-get install openjdk-8-jdk

3. Check the java version to see if the installation is successful:

$ java -version

The following words appear, indicating that the installation was successful

openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~16.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

 
 

Method 2: Install Oracle Java JDK from the command line

1. Install dependent packages:

$ sudo apt-get install python-software-properties

2. Add warehouse source:

$ sudo add-apt-repository ppa:webupd8team/java

3. Update the package list:

$ sudo apt-get update

4. Install java JDK:

$ sudo apt-get install oracle-java8-installer

You need to accept the agreement during the installation process:
Insert picture description here
5. Check the java version to see if the installation is successful:

$ java -version

The following words appear, indicating that the installation was successful

openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~16.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

 
 

Manually download the compressed package to install oracle Java JDK

1. Go to oracle Java official website to download JDK

http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Unzip to the specified directory (take jdk-8u144-linux-x64.tar.gz as an example)

  • Create a directory:
$ sudo mkdir /usr/lib/jvm
  • Unzip to that directory:
$ sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm

3. Modify environment variables:

$ sudo vi ~/.bashrc

Append the following at the end of the file:

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

Make the environment variable take effect immediately:

$ source ~/.bashrc

4. The system registers this jdk

$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300

5. Check the java version to see if the installation is successful:

$ java -version

The following words appear, indicating that the installation was successful

openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~16.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

Guess you like

Origin blog.csdn.net/weixin_43901865/article/details/112846730