Use CentOS7 to uninstall the original openjdk and install your own JDK1.8

Original link : https://blog.csdn.net/hui_2016/article/details/69941850

Regarding the changes and new features of JDK1.8 compared with the previous version, I will not elaborate here. After all, I have everything for a while. Since I don't say much, let's start!

prepare materials:

 

1. A virtual machine that has been installed on VMware. This article uses CentOS7. I will take this as an example. If you don’t know how to install it, you can refer to my first article. The above details how to install CentOS7  download Install centos7

 

2. jdk: jdk-8u11-linux-x64.tar.gz  official website to download jdk8

 

3. xshell remote operation virtual machine tool xshell download and installation please refer to my previous article (why use it to operate, because I think it is easy to operate and free.)   Download and install xshell

 

OK, the information is ready, now you can start

After successfully connecting to the installed virtual machine through the xshell tool, you can use the rpm -qa | grep java or rpm -qa | grep jdk command to query the system's own jdk (the four with arrows are the system's own) Note: No Don’t delete the three with arrows

Then use the command rpm -e --nodeps followed by the jdk name that comes with the system to delete the jdk that comes with the system,

例如: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

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

The next step is to install your own jdk, enter the local directory through the command cd /usr/local/, and use the ll (two lowercase L) commands or the ls command (ll itself is not a command, but an alias of the ls -l command , But it doesn’t matter, they are all viewed in the same way) List 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

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). Create , if you want to create a parent-child directory (parent/child) at once, you can pass 

mkdir -p parent/child/grandson to create)

After creation, enter the java directory cd java

I don’t know if you have used the plug-in to import the installation package online. If you have not used it before, you can install this plug-in through the yum -y install lrzsz command

 

 

After installing the plug-in, enter the rz command and press Enter, a window will pop up, and then you will find the jdk you downloaded in this window.

Note: The advantage of using the rz command is that the installation package imported by rz is located where you enter it, and will not go to the root directory

 

Double-click jdk or press open and you will enter the transfer interface

Sometimes there will be problems like the following, if it does, please close the window and re-enter the rz command and press Enter

 

This is normal

 

 

After the transfer is complete, ll command to view

 

 

Decompress jdk through the tar -zxvf {installation package name} command, such as: tar  -zxvf jdk-8u11-linux-x64.tar.gz I personally like to translate zxvf into Chinese, called

"Small prestige" so I find it convenient to remember Chuckle, don’t spray if you don’t like it

 

 

After decompression, the following screen appears

 

 

At this time, the installation package is useless, I usually delete the installation package through rm -f  jdk-8u11-linux-x64.tar.gz to delete the installation package -f means to delete without asking if you do not add -f in the delete When it will ask you if you want to delete the installation package, I added -f if I was sure to delete it. Having said that, let me say by the way 

Recursively delete the command without asking. Under what circumstances should you use this command, if you want to delete a directory, and there are directories or files in this directory, for example , you want to delete parent in a directory like parent/child/grandson All directories and files (including parent) can be used

rm -rf parent command can be deleted

 

 

After deleting the installation package, the environment variables are configured. Open the profile file disk through the vim /etc/profile command to configure the environment variables

 

 

After opening, press i to enter the insert mode and add environment variables at the end of the file

export JAVA_HOME=/usr/local/java/jdk1.8.0_11
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

 

 

 

After adding, save and exit. There are two commands for saving and exiting. The first one is: hold down the shift key and then double-press z twice (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 operated in non-insert mode (in insert mode, press the ESC key at the upper left corner of the keyboard to exit insert mode is non-insert mode).

 

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

 

 

Now you can test the jdk. Enter the javac command. If the following text appears, it means that the compilation is successful (if the language you used when you installed centos7 before was English, then the English formatted like this will appear)

 

Next, we use the java -version command to view the jdk information you installed

 

 

If the above information appears, it means that your own jdk is completely installed successfully. If you have any questions, you can leave a message under the comments. I will reply as soon as I see

 

 

If there is anything wrong with this article, please pass by the gods to point out, so as not to mislead others

 

Respect originality, please indicate the source if you want to reprint

 

 

 

 

Guess you like

Origin blog.csdn.net/u010472858/article/details/95210001