This is the 15th day of my participation in Gwen Challenge

1. Installation environment

Operating system: CentOS7 64-bit (Ali Cloud)

JDK version: 1.8

Tools: Xshell5, Xftp5

This article is through the Xshell5 tool remote connection Linux operation.

Check whether JDK has been installed in the system. Generally Linux uses the open source openJDK by default.

	 [root@localhost Desktop]# java -version
	 java version "1.6.0"
	 OpenJDK Runtime Environment (build 1.6.0-b09)
	 OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)
Copy the code

If the preceding information is displayed, openJDK is installed.

    rpm -qa | grep java    
    rpm -qa | grep jdk   
	 [root@localhost Desktop]# rpm -qa | grep java
	 [root@localhost Desktop]# rpm -qa | grep jdkJava 1.4.2 - GCJ compat - 1.4.2.0-40 JPP. 115 Java 1.6.0 - its 1.6.0.0-1.7 b09) el5Copy the code

OpenJDK has been installed. Uninstall openJDK from the system.

To uninstall a single program, run the RPM -e –nodeps XXX command. The command line:

RPM -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 RPM -e --nodeps java-1.6.00-openJDK-1.6.0.0-1.7.b09.el5Copy the code

Batch uninstall all installed programs whose names contain the JDK. The command line:

    rpm -qa | grep jdk | xargs rpm -e --nodeps 
Copy the code

Batch uninstall all installed programs whose names contain Java. The command line:

    rpm -qa | grep java | xargs rpm -e --nodeps  
Copy the code

If you can’t find the OpenJDK source, you can also uninstall the openJDK:

Yum -y remove Java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 yum -y remove Java java-1.6.0-openJDK-1.6.0.0-1.1.b09.el5Copy the code

When you check the JDK version, no information is displayed. The uninstallation is successful.

    [root@localhost Desktop]# java -version
    bash: /usr/bin/java: No such file or directory
Copy the code

Two, installation steps

Step 1: Download the installation package

To download JDK 1.8 in Linux, please go to the JDK installation file.

Since my Linux is 64-bit, I download jdK-8u161-linux-x64.tar.gz.

Download the installation package and upload it to the server

Step 2: Decompress the installation package

Upload the JDK installation package we downloaded to the server and decompress it

Decompress the decompression command

	 $ tar  -zxvf  jdk-8u161-linux-x64.tar.gz
Copy the code

After decompressing, you can see a directory named [jdk1.8.0_151] in the current directory, which stores related files

We are going to install the JDK in usr/ Java. We are going to create a new Java folder in usr

    mkdir /usr/java
Copy the code

Copy the data in jdk1.8.0_131 to the Java directory

Mv/home/cmfchina/jdk1.8.0 _151 / usr/JavaCopy the code

Third, modify environment variables

At this point, we finally need to modify the environment variable through the command

    vim /etc/profile
Copy the code

To edit the profile with the Vim editor, add the following content at the end of the file (press ‘I’ to edit) :

	export JAVA_HOME=/usr/local/ Java/jdk1.8.0 _151export JRE_HOME=${JAVA_HOME}/jre
	
	export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH 
	
	export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin 
	
	export PATH=$PATH:${JAVA_PATH}
Copy the code

Then, save and exit (press: wq!)

After saving, we also need to enable the environment variable configuration information to take effect, otherwise we have to restart the computer to take effect.

Make the command take effect, as shown in the figure

    source /etc/profile
Copy the code

Step 4. Test whether the installation is successful

If javac is used, command not found error is not found

Java version “1.8.0_151”

Echo $PATH to check if the environment variables you set are correct

The installation is complete