Install jdk environment in CentOS7-64
1. Review the following Linux commands before installing jdk:
1 、 rpm - qa | grep java
Command description:
rpm: management suite
-qa: use query mode, query all kits
grep: find matching strings in a file
java: find files containing java strings
2、rpm -e –nodeps java-x.x.x-gcj-compat-x.x.x.x-xxjpp.xxx
Command description:
rpm: management suite
-e: delete the specified suite
--nodeps: Do not verify package file dependencies
3、cp jdk-8u11-linux-x64.tar.gz /usr/local/src/
Command description:
cp: copy a file or directory
jdk-8u11-linux-x64.tar.gz: filename
/user/local/src: target directory to copy
4、tar -zxvf jdk-8u11-linux-x64.tar.gz
Command description:
tar: backup file
-zxvf
-z: Process backup files via gzip command
-x: restore file from backup file
-v: show the command execution process
-f: specify the backup file
jdk-8u11-linux-x64.tar.gz: filename
5、rm -f jdk-8u144-linux-x64.tar.gz
Command description:
rm: delete a file or directory
-f: Force deletion of file or directory
2. Uninstall jdk
1. Check whether the JDK and its version are installed in the current Linux system: java – version
2. View JDK information: rpm – qa | grep java
The displayed information is as follows:
The red box is the system's own java related files.
3. The uninstallation system comes with a java installation environment (there are several uninstalls): rpm -e --nodeps java-xxx-gcj-compat-xxxx-xxjpp.xxx
Among them, pay attention to the user's permissions during the uninstallation process. If the uninstallation is performed by an ordinary user, the following problems will occur. Use the su root command to switch to the root user.
4. Check whether the built-in JDK has been deleted successfully: java –version
If the above information appears, it means that the deletion has been successful. If it has not been deleted, you can use yum -y remove to delete the java-related files that have not been deleted.
3. Install jdk
1. Download JDK, the download address is:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Copy the JDK compressed package to /usr/local/src/ for backup:
3. Unzip jdk: tar -zxvf jdk-8u11-linux-x64.tar.gz
4. Delete jdk: rm -f jdk-8u11-linux-x64.tar.gz
5. Move the decompressed folder to the common folder where you install third-party software: mv jdk1.8.0_131 /usr/local/
6. Configure JDK environment variables
After the installation is complete, you need to configure the environment variables and edit the /etc/profile file:
vim /etc/profile
Add the following configuration at the end of the file:
export JAVA_HOME=/usr/local/jdk1.8.0_11/
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
Screenshot below:
7. Reload the /etc/profile file through the source command, so that the modified content is valid in the current shell window: source /etc/profile
8. Test whether the jdk is installed successfully.
Enter java -version to view the jdk version information:
As shown in the figure above, the jdk version is displayed normally, and the installation has been successful so far.