安装步骤
1. 从官网下载安装包保存到 /home/download 下面
2.下载后解压到指定目录,例如:/usr/java/jdk11
3. 解压压缩包
[root@localhost linux-x86-64]# cd /usr/java/jdk11
[root@localhost jdk11]#
[root@localhost jdk11]#
[root@localhost jdk11]# tar -zxvf jdk-11.0.19_linux-x64_bin.tar.gz
jdk-11.0.19/README.html
jdk-11.0.19/bin/jar
jdk-11.0.19/bin/jarsigner
jdk-11.0.19/bin/java
jdk-11.0.19/bin/javac
略
jdk-11.0.19/man/man1/rmiregistry.1
jdk-11.0.19/man/man1/serialver.1
jdk-11.0.19/man/man1/unpack200.1
jdk-11.0.19/release
[root@localhost jdk11]#
4. 修改/etc/profile , 增加下面四项。
- export JAVA_HOME=/usr/java/jdk11/jdk-11.0.19
- export JRE_HOME=${JAVA_HOME}/jre
- export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
- export PATH=${JAVA_HOME}/bin:$PATH
/etc/profile文件为系统的每个用户设置环境变量信息,此文件的修改会影响到所有用户
[root@localhost jdk11]# vim /etc/profile
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmung
export LANG=zh_CN
export JAVA_HOME=/usr/java/jdk11/jdk-11.0.19
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
"/etc/profile" 83L, 2008C 已写入
5.使用source命令更新环境变量修改内容
修改后查看版本会发现JDK版本没有变化,因为/etc/profile 修改没有生效, 使用source /etc/profile命令更新
[root@localhost jdk11]#
[root@localhost jdk11]#
[root@localhost jdk11]# java -version
openjdk version "1.8.0_372"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_372-b07)
OpenJDK 64-Bit Server VM (Temurin)(build 25.372-b07, mixed mode)
[root@localhost jdk11]#
[root@localhost jdk11]# source /etc/profile
[root@localhost jdk11]#
[root@localhost jdk11]# java -version
java version "11.0.19" 2023-04-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.19+9-LTS-224)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.19+9-LTS-224, mixed mode)
[root@localhost jdk11]#
[root@localhost jdk11]#
常见问题
1. unzip command not found
使用yum install -y unzip zip 完成安装
[root@localhost ~]# yum install -y unzip zip
Loaded plugins: fastestmirror
Determining fastest mirrors
base: mirrors.bfsu.edu.cn
extras: mirrors.bfsu.edu.cn
updates: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
updates/7/x86_64/primary_db
2. vim command not found
一般默认vim安装的是简版,可以使用rpm -qa|grep vim 查看信息, 如果安装的是简版使用yum -y install vim 完整安装
[root@localhost jdk8u372-b07]#
[root@localhost jdk8u372-b07]# rpm -qa|grep vim
vim-simple-7.4.629-8.el7_9.x86_64
[root@localhost jdk8u372-b07]#yum -y install vim
[root@localhost jdk8u372-b07]#
[root@localhost jdk8u372-b07]# rpm -qa|grep vim
vim-common-7.4.629-8.el7_9.x86_64
vim-minimal-7.4.160-5.el7.x86_64
vim-filesystem-7.4.629-8.el7_9.x86_64
vim-enhanced-7.4.629-8.el7_9.x86_64
上一篇:编译时不好的注释会让代码丢失并产生问题