Detailed process of installing JDK under CentOS7

Open JDK is generally installed on Linux. The difference between OpenJDK and JDK: http://www.cnblogs.com/sxdcgaq8080/p/7487369.html

 

Start the installation steps below:

-------------------------------------------------- ------------------------first step----------------------- ------------------------------------------------

The first step is to uninstall the OpenJDK and related java files that come with the system

① Type in the command window:

java -version

You can see the OpenJDK version information that comes with the system.

 

②Type in the command window:

rpm -qa | grep java

Command description:

rpm management suite    

-qa use query mode, query all packages

grep finds matching strings in a file

java find files containing java strings

 

In the above file:

The following can be deleted

java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64

noarch files can be deleted without deleting

python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2016g-2.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch

 

③ Type in the command window:

rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64

But there will be an error, because under the ordinary user sxd user, there is no permission to operate these files.

solve:

  Type in the command window:

su root

Enter the root user, you can have permission to operate these files.

 

For the complete command to delete a file, type in the command window:

rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
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

Command introduction:

rpm management suite  

-e delete the specified package

--nodeps don't verify package file dependencies

 

 

④Check whether it has been deleted successfully

Type in the command window:

java -version

The representative has been deleted successfully.

 

⑤ If they have not been deleted, use yum -y remove to delete them

-------------------------------------------------- ----------------------------Step 2------------------- -------------------------------------------------- --------

The second step is to download the latest stable JDK

[Note]: Under which user the JDK is installed is for which user

①The download address is

  The latest version download address: http://www.oracle.com/technetwork/java/javase/downloads/index.html

  Download address of historical version: http://www.oracle.com/technetwork/java/javase/archive-139210.html   

② Paste the address into the browser address bar

  

Downloading through the browser will default to the download directory of the current logged-in user.
For example, the current logged-in user is root, then the download location is "/root/download/jdk-8u144-linux-x64.tar.gz".

slow download

 

 

The current user is the sxd user, so you can see that the downloaded JDK file is located in /home/sxd/download/jdk-8u144-linux-x64.tar.gz

 

 ③ After the download is complete, copy the JDK compressed package to /usr/local/src/ for backup

Type the command:

cp jdk-8u144-linux-x64.tar.gz /usr/local/src/

Command description:

cp copies files or directories

jdk-8u144-linux-x64.tar.gz filename

/user/local/src target directory to copy

Something went wrong:

When cp copies files, there is a problem of insufficient permissions, which explains why when the JDK compressed file is just viewed above, the file name is red.

 

Instructions for modifying file or directory permissions: http://www.cnblogs.com/sxdcgaq8080/p/7498906.html

 

④ Modify the permissions of the JDK compressed file, and then perform the copy operation

Type at the command line:

chmod 755 jdk-8u144-linux-x64.tar.gz

Then type:

ls -al

You can see the effect:

The file name has been displayed in green, and the beginning of the line can actually see that the permissions have been changed to: -rwxr-xr-x

Next, type:

 

Change the permission to 777, still can't cp operation

 

⑤Finally enter the root user and perform the copy operation

Type:

This is copied successfully.

 

-------------------------------------------------- ---------------------third step-------------------------- -------------------------------------------------- -

The third step is to decompress the JDK

①Copy the /home/sxd/download/jdk-8u144-linux-x64.tar.gz file to /usr/java

At the command line type:

cp jdk-8u144-linux-x64.tar.gz /usr/java

 

②Unzip the JDK compressed file in the java directory

Type in the command window:

tar -zxvf jdk-8u144-linux-x64.tar.gz

Command introduction:

tar backup file

-zxvf     

-z Process backup files via gzip command

-x restore file from backup file

-v show the command execution process

-f specifies the backup file

jdk-8u144-linux-x64.tar.gz filename

 

The file decompression is complete.

 

③ Delete the JDK compressed package

Type at the command line:

rm -f jdk-8u144-linux-x64.tar.gz

Command Explanation:

rm delete a file or directory

-f Force deletion of file or directory

 

 

-------------------------------------------------- -----------------------------------the fourth step------------ -------------------------------------------------- --------------------------

The fourth step configures the JDK environment variables

①Edit global variables

Type at the command line:

vim /etc/profile

Command description:

vim text editor

/etc/profile global variable file

 In the text editing state, the cursor goes to the last line of the file, and the keyboard is pressed:

i

Enter insert state:

Paste the following on the last line of text:

Note that JAVA_HOME=/usr/java/jdk1.8.0_144 is your own directory

#java environment
export JAVA_HOME=/usr/java/jdk1.8.0_144
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin

[Note]: CentOS6 is JAVAHOME, CentOS7 is {JAVA_HOME}

 

 

keyboard:

ESC

shift+q

 

keyboard:

qw!

write and force quit.

If it doesn't work, you can use the keyboard:

x

One meaning is to save and exit.

 

 -------------------------------------------------- -----------------------the fifth step------------------------ -------------------------------------------------- -

The fifth step is to make the environment variables just set take effect and check whether the installation is successful

①Make the environment variable you just set take effect

 Type:

source /etc/profile

 source /etc/profile或 . /etc/profile

 

 ②Check whether the configuration is successful

Type:

java -version

But if there is an error after linux environment variable configuration..-bash: /usr/local/java/jdk1.7.0_55/bin/java: /lib/ld-linux.so.2: bad ELF interpreter

Run the command: yum install glibc.i686 

However, if you run the java -version command directly, an error will be reported. You need to use the source /etc/profile again to make the file take effect, because it is found that this file has been opened during the installation process. If you run the java -version command at this moment, it will prompt that the installation is successful.

 

Just follow the prompts to confirm the installation,...try it

 

 ======================================================================================================= ===================================================== ===

 

Finally completed, the steps are very simple, but if you don't know the entry command, you can refer to:

http://www.cnblogs.com/sxdcgaq8080/p/7470796.html

Study all the commands one by one.

 

Guess you like

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