First, the preparatory work:
1. The login server, to root (su - root, and then enter the password, press Enter), into the root directory: cd /
2. Go to the directory you want to install jdk, you can create a java directory, execute the following command:
cd /usr/local/
mkdir java
Second, download the installation package
1. Open the official website to download interface: https: //www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2. download the package, as shown below
After the download is complete as shown below:
To download system and their matching packet, performing cat / proc / version in linux root directory, the results as shown below
Three download package uploaded to linux, there are 2 ways:
Method 1: Use FTP to upload, download Xftp after connecting to the server
Second way: yum install rz sz, yum install lrzsz to install successfully executed on linux, execute rz under / usr / local / java, press the Enter key, the pop-up window, select the downloaded installation package, click Open to upload, As long as you can wait for the upload is complete, this way a relatively slow way, if there is FTP tools, we recommend using FTP upload tool
IV. Extracting package
tar -xzvf jdk-8u221-linux-x64.tar.gz
V. configuration environment variable
Execute cd /, into the root directory
After performing vim / etc / profile, press i, add the following text at the end, press the ESC key, enter: wq save and exit
JAVA_HOME=/usr/local/java/jdk1.8.0_221
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
Screenshot below:
VI. The JDK to take effect, restart the server or the configuration file to take effect
Reboot the server: reboot command or sudo shutdown -r now
不重启使配置文件生效:执行命令source /etc/profile
七.检查JDK是否生效
执行java -version,显示如下图即表示安装成功