Several methods of installing jdk in CentOS7.4 and configuring environment variables

1. Download jdk

jdk download address: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Download jdk-8u152-linux-x64.rpm or jdk-8u152-linux-x64.tar.gz (select the corresponding package according to your system bitness)

As shown in the figure:

 

2. Install jdk

1. Because the CentOS7.4 system I installed comes with jdk1.8, so in order to demonstrate how to install jdk, I need to uninstall the jdk that comes with the system first

View the version of the current system jdk: java -version

List packages matching installed java: yum list installed | grep java

Uninstall the installed jdk: (yum command reference: http://man.linuxde.net/yum )

yum -y remove java-1.7.0-openjdk*  

yum -y remove java-1.8.0-openjdk*

When the results show up! , it means the uninstallation is successful.

2. Install jdk (three methods are introduced)

Method 1: Use yum source to install jdk (this method does not need to configure environment variables)

View the java installation package in the yum library: yum -y list java*

Install all java programs of the required jdk version: yum -y install java-1.8.0-openjdk*

(After installation, the default installation directory is: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64)

When the results show up! That is, the installation is complete.

Check java version: java -version

 

Method 2: Install jdk with rpm (you can use the man rpm command to view the help documentation of rpm)

Use Xftp to upload the downloaded jdk-8u152-linux-x64.rpm to CentOs, I put it here under /home/lisonglin 

Install using the rpm command:  rpm -ivh jdk-8u152-linux-x64.rpm

(installed in the /usr/java directory by default, no need to configure environment variables)

 

Method 3: Manually decompress the JDK compressed package, and then set the environment variables

Use Xftp to upload the downloaded jdk-8u152-linux-x64.tar.gz to CentOs, I put it here under /home/lisonglin

First uninstall the jdk previously installed by rpm (if it has not been installed, you can skip this step)

Query the name of the jdk installed before: rpm -qa | grep jdk

Uninstall jdk: rpm -e --nodeps jdk1.8 (you can also use the full name jdk1.8-1.8.0_152-fcs.x86_64 here)

Uninstallation complete!

1. Copy the installation package to the /usr/java directory (you can choose the directory yourself): cp jdk-8u152-linux-x64.tar.gz /usr/java

2. Switch to the /usr/java directory: cd /usr/java

3. Unzip the package: tar -zxvf jdk-8u152-linux-x64.tar.gz 

The decompression is successful (the table JDK has been installed successfully, you can view the jdk folder)

At this point the java -version command cannot be used yet:

4. Configure environment variables

Use vim /etc/profile to edit the profile file input: vim /etc/profile

Append the following to the file:

#set java environment
JAVA_HOME=/usr/java/jdk1.8.0_152
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH

Notes:

JAVA_HOME indicates the JDK installation path, which is the path selected during installation. This path includes lib, bin, jre and other folders (tomcat and Eclipse need to rely on this variable to run).

CLASSPATH is the path of the java loaded class (class or lib). Only the class in the classpath can be recognized by the java command. Set: .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib. . in the value of the CLASSPATH variable represents the current directory

PATH enables the system to recognize java commands in any path, set to: $JAVA_HOME/bin:$JRE_HOME/bin.

Special attention: There is no symbol at the end of the environment variable value, and different values ​​are separated by : (used in windows; ).

5. Make the configuration file take effect: source /etc/profile

6. Test whether the configuration is successful

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324517428&siteId=291194637