linux下安装OpenJDK 1.8
1. 使用yum查找jdk: yum search java|grep jdk
[root@iasdasd jvm]# yum search java|grep jdk Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Last metadata expiration check: 2:11:26 ago on Wed 09 Feb 2022 07:18:56 PM CST. java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK 8 accessibility connector java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment java-1.8.0-openjdk-headless-slowdebug.x86_64 : OpenJDK 8 Runtime Environment unoptimised with full debugging on java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed in a single archive java-1.8.0-openjdk-slowdebug.x86_64 : OpenJDK 8 Runtime Environment unoptimised with full debugging on java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in a single archive java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11 java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking java-17-openjdk.x86_64 : OpenJDK 17 Runtime Environment java-17-openjdk-demo.x86_64 : OpenJDK 17 Demos java-17-openjdk-devel.x86_64 : OpenJDK 17 Development Environment java-17-openjdk-headless.x86_64 : OpenJDK 17 Headless Runtime Environment java-17-openjdk-javadoc.x86_64 : OpenJDK 17 API documentation java-17-openjdk-javadoc-zip.x86_64 : OpenJDK 17 API documentation compressed in a single archive java-17-openjdk-jmods.x86_64 : JMods for OpenJDK 17 java-17-openjdk-src.x86_64 : OpenJDK 17 Source Bundle java-17-openjdk-static-libs.x86_64 : OpenJDK 17 libraries for static linking
2. 执行安装命令:yum install java-1.8.0-openjdk
安装成功后,默认安装路径在/usr/lib/jvm/下边,
如/usr/lib/jvm/java-1.8.0-openjdk-1xxxxxxxx 每个人的可能不同,下面配置环境会用到这个路径,要记住,
查看安装路径(如下所示):
which java
ls -lrt /usr/bin/java
[root@preproduct1 ~]# which java /usr/bin/java [root@preproduct1 ~]# echo $JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 [root@preproduct1 ~]# ls -lrt /usr/bin/java lrwxrwxrwx 1 root root 22 Feb 13 10:40 /usr/bin/java -> /etc/alternatives/java [root@preproduct1 ~]# ls -lrt /etc/alternatives/java lrwxrwxrwx 1 root root 73 Feb 13 10:40 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java [root@preproduct1 ~]# cd /usr/lib/jvm [root@preproduct1 /usr/lib/jvm]# ll total 4 lrwxrwxrwx 1 root root 26 Feb 13 10:44 java -> /etc/alternatives/java_sdk lrwxrwxrwx 1 root root 32 Feb 13 10:44 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0 lrwxrwxrwx 1 root root 40 Feb 13 10:44 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk drwxr-xr-x 7 root root 4096 Feb 13 10:44 java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 lrwxrwxrwx 1 root root 34 Feb 13 10:44 java-openjdk -> /etc/alternatives/java_sdk_openjdk lrwxrwxrwx 1 root root 21 Feb 13 10:40 jre -> /etc/alternatives/jre lrwxrwxrwx 1 root root 27 Feb 13 10:40 jre-1.8.0 -> /etc/alternatives/jre_1.8.0 lrwxrwxrwx 1 root root 35 Feb 13 10:40 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk lrwxrwxrwx 1 root root 51 Feb 13 10:40 jre-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 -> java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre lrwxrwxrwx 1 root root 29 Feb 13 10:40 jre-openjdk -> /etc/alternatives/jre_openjdk
3 验证java是否安装成功
-
查看java版本:java -version
-
# java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
-
查看java是否可用:javac
-
# javac -bash: javac: command not found
错误原因:默认安装完只有运行环境,java安装目录下只有jre文件夹
4 安装开发环境
yum install java-1.8.0-openjdk-devel.x86_64
再次输入javac说明安装成功
5 设置环境变量
修改/etc/profile文件:vi /etc/profile
在profile文件末尾新增如下内容:
-
#set java environment JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-xxxx 这就是刚刚说的那个路径的名称 JRE_HOME=$JAVA_HOME/jre CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME JRE_HOME CLASS_PATH PATH
按shift+: 再按wq!保存退出 -
source /etc/profile
echo $JAVA_HOME
再次查看应该有东西了