First, download the JDK
Click to download: the JDK-8u211-Linux-x64.tar.gz
be selected and the corresponding version number of bits, and put the file CentOS relevant directory to /java/jdk
the directory, for example, execute makdir /java/jdk
the command to create the directory; use Xftp tool JDK downloaded compressed file in it.
Second, unzip
# 切换到 JDK 压缩包所在的目录
$ cd /java/jdk
# 将压缩包解压缩到当下目录
$ tar -zxvf jdk-8u211-linux-x64.tar.gz
# tar 命令中的参数说明:
# -z 支持gzip解压文件
# -x 从压缩的文件中提取文件
# -v 显示操作过程
# -f 指定压缩文件
JDK unpacked directory is: /java/jdk/jdk_1.8.0_211/
This is the directory which will be configuration environment variable JAVA_HOME
values of the variables;
Third, the environment variable
Configuring JDK environment variables in three ways: a global permanent, the current user permanent, temporary entry into force . According to specific needs, you can choose one.
1, the global permanent
This method is effective for all users. Execute commands vim /etc/profile
to edit the /etc/profile
file, press the keyboard ito enter edit mode, add the following text at the end:
#set java environment
export JAVA_HOME=/java/jdk/jdk_1.8.0_211
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH
Turn the keyboard Esc-> ( Shift+ :) -> q-> w, that is, save and exit edit mode. Then execute the command source /etc/profile
for the changes to take effect immediately.
Note: This method is also another form, you do not need to modify /etc/profile
files in the directory but to /etc/profile.d/
create a new file jdk.sh
and edit. To do: execute the command vim /etc/profile.d/jdk.sh
, vim
the command will determine when /etc/profile.d/
the directory does not exist in the file jdk.sh
, it will automatically create a jdk.sh
file and edit. Editorial content above, finally execute the command source /etc/profile.d/jdk.sh
to take effect.
2, the current user permanent
This method is only effective for the user's current login, execute commands vim ~/.bash_profile
to edit the current user's home directory in the /home/用户名/.bash_profile
file, add content above the end of the article, and execute the command source ~/.bash_profile
to take effect.
3, temporary entry into force
Run the command directly export PATH=$PATH:/java/jdk/jdk_1.8.0_211/bin
, using this method, it will only take effect for the current session.
Fourth, verification
Finally, execute the command java -version
to verify JDK environment variable configuration is successful, if the java version information display indicates normal JDK installation was successful. At this time, /java/jdk/jdk-8u211-linux-x64.tar.gz
no longer with, if not required it can be deleted.