Use CentOS 7.5 to uninstall the built-in jdk and install your own JDK1.8

This article mainly introduces how to install the JDK in the Linux environment, because in the Linux environment, Java is often inseparable, so the author will share with you the process of jdk1.8.

1. Installation environment

Two, installation steps

0、 We first have a clean Linux environment
Proceed as follows:

[ root@itheima ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804(Core)[root@itheima ~]# ll
Total amount 0

1、 Check the jdk version in the linux system

[ root@itheima ~]# java -version

Shown as follows:

openjdk version "1.8.0_161"
OpenJDK Runtime Environment(build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM(build 25.161-b14, mixed mode)

2、 Check the jdk installation package under linux

[ root@itheima ~]# rpm -qa | grep java
or
[ root@itheima ~]# rpm -qa | grep jdk

Shown as follows:

python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
tzdata-java-2018c-1.el7.noarch
java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64
or
copy-jdk-configs-3.3-2.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64

3、 Uninstall openjdk first (4 files in total)

[ root@itheima ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
[ root@itheima ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
[ root@itheima ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
[ root@itheima ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64

After the deletion, you can use the rpm -qa | grep java or rpm -qa | grep jdk command to check whether it is deleted

[ root@itheima ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2018c-1.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
[ root@itheima ~]# rpm -qa | grep jdk
copy-jdk-configs-3.3-2.el7.noarch
[ root@itheima ~]# 

4、 Install new Oracle JDK1.8
Use the command: cd /usr/local/ to enter the local directory, and use the ll (two lowercase L) command or the ls command (ll itself is not a command, just an alias for the ls -l command) All non-implicit files in the current directory. If you want to see the hidden (starting with ., such as: .test.txt) file information, you can use ll -a to view, as follows:

[ root@itheima ~]# cd /usr/local/[root@itheima local]# ll
Total amount 0
drwxr-xr-x.2 root root 64 Nov 112018 bin
drwxr-xr-x.2 root root 64月112018 etc
drwxr-xr-x.2 root root 64月112018 games
drwxr-xr-x.2 root root 64 Nov 112018 include
drwxr-xr-x.2 root root 64 Nov 112018 lib
drwxr-xr-x.2 root root 64 Nov 112018 lib64
drwxr-xr-x.2 root root 64 Nov 112018 libexec
drwxr-xr-x.2 root root 64 Nov 112018 sbin
drwxr-xr-x.5 root root 49 Nov 200:50 share
drwxr-xr-x.2 root root 64 Nov 112018 src

After entering the local directory, use the mkdir java command to create a java directory to store your own jdk.
Extension: If you want to create multiple directories at the same level at one time, you can use mkdir brother1 brother2 (if you want to create more, just add it at the end, separated by spaces). If you want to create a parent-child directory (parent/child) at once, you can create it by mkdir -p parent/child/grandson, as follows:

[ root@itheima local]# mkdir java
[ root@itheima local]# ll
Total amount 0
drwxr-xr-x.2 root root 64 Nov 112018 bin
drwxr-xr-x.2 root root 64月112018 etc
drwxr-xr-x.2 root root 64月112018 games
drwxr-xr-x.2 root root 64 Nov 112018 include
drwxr-xr-x.2 root root 611/819:01 java
drwxr-xr-x.2 root root 64 Nov 112018 lib
drwxr-xr-x.2 root root 64 Nov 112018 lib64
drwxr-xr-x.2 root root 64 Nov 112018 libexec
drwxr-xr-x.2 root root 64 Nov 112018 sbin
drwxr-xr-x.5 root root 49 Nov 200:50 share
drwxr-xr-x.2 root root 64 Nov 112018 src

5、 Use the SSH link tool SecureCRT to connect to the Linux system and open the SFTP session
Upload the downloaded jdk installation package jdk-8u191-linux-x64.tar.gz to the /usr/local/java directory of the Linux system

sftp> pwd
/root
sftp> cd /usr/local/java/
sftp> pwd
/usr/local/java
sftp> put -r "C:\Users\Bruce\Desktop\jdk-8u191-linux-x64.tar.gz"
Uploading jdk-8u191-linux-x64.tar.gz to /usr/local/java/jdk-8u191-linux-x64.tar.gz
 100 % 187259KB  46814KB/s 00:00:04     
C:\Users\Bruce\Desktop\jdk-8u191-linux-x64.tar.gz:191753373 bytes transferred in4seconds(46814 KB/s)
sftp> put -r "C:\Users\Bruce\Desktop\jdk-8u191-linux-x64.tar.gz"
Uploading jdk-8u191-linux-x64.tar.gz to /usr/local/java/jdk-8u191-linux-x64.tar.gz
 100 % 187259KB  62419KB/s 00:00:03     
C:\Users\Bruce\Desktop\jdk-8u191-linux-x64.tar.gz:191753373 bytes transferred in3seconds(62419 KB/s)
sftp>

After the transfer is complete, ll command to view

[ root@itheima java]# ll
Total amount 187260-rw-r--r--.1 root root 19175337311 month 817:07 jdk-8u191-linux-x64.tar.gz
[ root@itheima java]# 

6、 Unzip the jdk-8u191-linux-x64.tar.gz installation package

[ root@itheima java]# tar -zxvf jdk-8u191-linux-x64.tar.gz

After decompression, the following appears:

............
jdk1.8.0_191/jre/lib/fontconfig.SuSE.10.properties.src
jdk1.8.0_191/jre/lib/fontconfig.SuSE.11.bfc
jdk1.8.0_191/jre/COPYRIGHT
jdk1.8.0_191/jre/THIRDPARTYLICENSEREADME-JAVAFX.txt
jdk1.8.0_191/jre/Welcome.html
jdk1.8.0_191/jre/README
jdk1.8.0_191/README.html
[ root@itheima java]# ll
Total amount 187260
drwxr-xr-x.710143245 October 620:55 jdk1.8.0_191
- rw-r--r--.1 root root 19175337311 month 817:07 jdk-8u191-linux-x64.tar.gz

At this time, the installation package is useless. I usually delete the installation package and delete the installation package through rm -f jdk-8u191-linux-x64.tar.gz.
Here -f means not to ask for deletion. If you don't add -f, it will ask you if you want to delete the installation package. If you are sure to delete, add -f.
If you want to delete a directory and there are directories or files in this directory, such as parent/child/grandson, you can use rm to delete all the directories and files (including parent) under the parent in such a directory -rf parent command can be deleted. rm -rf parent means to delete recursively without asking.

[ root@itheima java]# rm -rf jdk-8u191-linux-x64.tar.gz 
[ root@itheima java]# ll
Total amount 0
drwxr-xr-x.710143245 October 620:55 jdk1.8.0_191
[ root@itheima java]# 

7、 Set environment variables
Open the profile file disk to configure environment variables through the vim /etc/profile command

[ root@itheima java]# vim /etc/profile

After opening, press i to enter insert (insert) mode, add environment variables at the end of the file, the content is as follows:

JAVA_HOME=/usr/local/java/jdk1.8.0_191
JRE_HOME=/usr/local/java/jdk1.8.0_191/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

After adding, save and exit. There are two commands for saving and exiting. The first is: hold down the shift key and then double-press z (this is what I often use because it is convenient and fast), the second is :wq command, there is a command to exit without saving :q! Note: The above three commands are all in non-insert mode (in insert mode, press the Esc key in the upper left corner of the keyboard to exit insert mode, which is wrong Insert mode).

8、 After saving, enter: source /etc/profile command to make the environment variable just configured take effect

[ root@itheima java]# source /etc/profile
[ root@itheima java]# 

9、 Test whether the jdk is installed successfully
Enter the javac command. If the following text appears, the compilation is successful (if the language you used when you installed centos7 was English, then the English formatted like this appears)

[ root@itheima java]# javac
usage: javac <options><source files>
among them,Possible options include:-g Generate all debugging information
 - g:none does not generate any debugging information
 - g:{lines,vars,source}Only generate some debugging information
 - nowarn does not generate any warnings
 - verbose prints messages about what the compiler is doing
 - deprecation output the source location using the obsolete API
 - classpath <path>Specify where to find user class files and annotation handlers
 - cp <path>Specify where to find user class files and annotation handlers
 - sourcepath <path>Specify where to find the input source file
 - bootclasspath <path>Override the location of the boot file
 - extdirs <table of Contents>Override the location of installed extensions
 - endorseddirs <table of Contents>Override the location of the signature path
 - proc:{none,only}Control whether to perform annotation processing and/Or compile.
 - processor <class1>[,<class2>,<class3>...]The name of the annotation handler to run;Bypass the default search process
 - processorpath <path>Specify where to find annotation handlers
 - parameters generate metadata for reflection of method parameters
 - d <table of Contents>Specify where to place the generated class files
 - s <table of Contents>Specify where to place the generated source files
 - h <table of Contents>Specify where to place the generated native header file
 - implicit:{none,class}Specify whether to generate class files for implicit reference files
 - encoding <coding>             指定源文件使用的字符coding
 - source <Release>              提供与指定Release的源兼容性
 - target <Release>Generate class files for specific VM versions
 - profile <Configuration file>            请确保使用的 API 在指定的Configuration file中可用
 - version version information
 - help output a summary of standard options
 - A keyword[=value]Options passed to the annotation handler
 - X output a summary of non-standard options
 - J<mark>Directly<mark>Passed to the runtime system
 - Werror terminates compilation when warning
 @< file name>                     从文件读取选项和file name

[ root@itheima java]# 

Or enter java -version

[ root@itheima java]# java -version
java version "1.8.0_191"Java(TM) SE Runtime Environment(build 1.8.0_191-b12)
Java HotSpot(TM)64-Bit Server VM(build 25.191-b12, mixed mode)[root@itheima java]# 

If the above information appears, it means that your own jdk is completely installed successfully! ! !

Reference link:
  https://blog.csdn.net/hui_2016/article/details/69941850
  https://www.cnblogs.com/Dylansuns/p/6974272.html

Recommended Posts

Use CentOS 7.5 to uninstall the built-in jdk and install your own JDK1.8
Centos7 uninstall openJdk, and install JDK1.8
CentOS Discovery Road 2---Use rpm to install JDK
How to install and use Docker on CentOS 7
How to install and use Composer on CentOS 8
CentOS7 uninstall OpenJDK, and then install Oracle JDK
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and use Curl on CentOS 8
How to install and uninstall tomcat on centos
How to install and use Cockpit on CentOS 8/RHEL 8
Centos 7 install jdk and package service service
CentOS7.3 install iptables and detailed use
Install and use docker under CentOS 6.8
CentOS7 install and use SQL Server
Use VMware15 to install Linux (CentOS6.5)
Detailed steps to install virtual machines with VMware 15 and use CentOS 8
Three ways to install JDK under CentOS
How to install offline JDK1.8 on centos7.0
Centos8 use yum to install rabbitmq tutorial
CentOS install jdk
VMware Fusion install CentOS7 and configure the network
How to install and configure Elasticsearch on CentOS 7
How to install and use Docker on Ubuntu 20.04
How to install and configure VNC on CentOS 8
The easiest way to install Chrome on CentOS 6
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
Centos7.2 compile and install way to build phpMyAdmin
How to install and use Docker on Ubuntu 16.04
How to install and configure Redmine on CentOS 8
Install centos7 and connect
CentOS 7 system to view the system version and machine digits
How to install and use MySQL Workbench on Ubuntu 18.04
How to install and configure NFS server on CentOS 8
CentOS7 install JDK8, tomcat8
Centos7 to install the correct posture of Tomcat8 and set the boot self-start practice notes
Centos 7 install JDK (Linux install jdk)
Compile and install the open source EDA tool-Surelog on CentOS8
How to install and configure Postfix mail server on CentOS8
How to install JDK and Mysql on Ubuntu 18.04 linux system
Use Jexus 5.8.2 to deploy and run Asp.net core under Centos
Detailed steps to install and configure k8s cluster in centos 7
CentOS 7 install JAVA environment (JDK 1.8)
CentOs7.3 compile and install Nginx 1.9.9
Centos7.6 method to install Tomcat-8.5.39
CentOS 7 install Mono and MonoDevelop
Centos compile and install Git
Centos6.5 install and configure mongodb
Tencent Cloud Centos install jdk8
centos7 kvm installation and use
CentOS7 install python3 and pip3
Install Java JDK8 under CentOS6
CentOS7 install OracleJDK and JRE