Since the centos7-dvd image selected comes with open jdk, it needs to be uninstalled. First query the built-in jdk:
rpm -qa | grep java
There will be 7 things with java names. Delete the files with openjdk among them. The command is as follows:
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
Execute again rpm -qa | grep java
command, there are only three left:
javapackages-tools-3.4.1-11.el7.noarch tzdata-java-2016g-2.el7.noarch python-javapackages-3.4.1-11.el7.noarch
Then install the jdk you need, first enter the local
directory:
cd /usr/local/
in Create a folder under this directory and name it jdk to store jdk files. Download file:
// wget 地址 wget
Get the url by right-clicking -> copy the link address, and then execute the command. It feels so good and the download speed is so fast!
Then execute the command:
tar -zxvf jdk-8u131-linux-x64.tar.gz
The result is an error, the error message:
gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
After searching online for a long time, I finally found the solution. First, use the file
command to view the real attributes of the file:
file jdk-8u131-linux-x64.tar.gz
Display the result:
[root@localhost jdk]# file jdk-8u131-linux-x64.tar.gz jdk-8u131-linux-x64.tar.gz: HTML document, ASCII text, with very long lines, with CRLF line terminators
It turns out that the downloaded web page (html) is what I said about a few hundred megabytes of stuff? It opens in seconds. Then you can only download it manually, and then execute the rz
command, select the downloaded file and transfer it to the Linux virtual machine, and perform decompression:
tar -zxvf jdk-8u131-linux-x64.tar.gz
The decompressed file is:
drwxr-xr-x. 8 10 143 4096 3月 15 16:35 jdk1.8.0_131
Delete the compressed file (optional):
rm -f jdk-8u131-linux-x64.tar.gz
Configure environment variables:
vim /etc/profile
Enter i
to enter edit mode and add environment variables at the end of the file:
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_131 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin
Press the esc
key and enter wq
(save and exit).
After saving, make the newly configured environment take effect:
source /etc/profile
Check whether the jdk installation is complete:
java -version
Display the result:
[root@localhost jdk]# java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
indicates that the configuration is successful.
The above is the detailed content of How to configure custom JDK in CentOS7. For more information, please follow other related articles on the PHP Chinese website!