Install JDK from Oracle official website
Choose to download the JDK version you want from the JDK official website. After the download is complete, upload the JDK installation package to be installed to the folder specified by the Linux system, and enter the command into this folder.
1 Enter the root directory and create a folder soft to save uploaded files.
This step is not necessary, this operation is only for the convenience of later software and document management.
Use XFTP to upload the local file JDK source code package to the directory specified by the Linux system soft
2 Enter the /usr/local/ directory to create a software directory: used to store various decompression software
3 Create a jdk directory under the software directory to save the decompressed jdk
4 Unzip the JDK file to the /usr/local/software/jdk directory (this must exist at present)
tar -xzvf jdk-8u181-linux-x64.tar.gz -C /usr/local/software/jdk
5 Rename the directory name
mv jdk1.8.0_181 jdk8
6 Configure environment variables
Linux environment variable configurations are all in: /etc/profile file
VIM commands to edit files (it is recommended to copy a source file as a backup before editing)
vim /etc/profile
In edit mode, add the following at the end or beginning:
JAVA_HOME=/usr/local/software/jdk/jdk8
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
Note: If you need to install jdk11 or other versions later, after the installation is complete, directly modify the environment variables when
JAVA_HOME
For
example, if we need to change to jdk11 in the later stage, after we have installed jdk11 (for example, the installation path is the same as above), we only need to modify the /etc/profile file as
JAVA_HOME=/usr/local/software/jdk/jdk11
Just reload, if the reload is still the previous version, then disconnect the terminal, reconnect, or restart the server.
Press ctrl+c to stop editing, then: wq to save and exit
7 Reload the configuration file
(reload the system configuration file, so that the configuration can take effect immediately without restarting)
source /etc/profile
8 Check the newly installed JDK
java -version
java
javac