1. 使用yum查找jdk: yum search java|grep jdk
2. 执行安装命令: yum install java-1.8.0-openjdk
安装成功后,默认安装路径在/usr/lib/jvm/下边,
如/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el6_9.x86_64
查看安装路径(如下所示):
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/alte rnatives/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
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
安装完可看到java安装目录下出现bin、lib等文件夹:
[root@preproduct1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64]# l
total 20
drwxr-xr-x 2 root root 4096 Feb 13 10:44 bin
drwxr-xr-x 3 root root 4096 Feb 13 10:44 include
drwxr-xr-x 4 root root 4096 Feb 13 10:40 jre
drwxr-xr-x 3 root root 4096 Feb 13 10:44 lib
drwxr-xr-x 2 root root 4096 Feb 13 10:44 tapset
再次输入javac说明安装成功
# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
5. 设置环境变量
修改/etc/profile文件: vi /etc/profile
在profile文件末尾新增如下内容:
#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
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
使环境变量生效:source /etc/profile
[root@preproduct1 /usr/lib/jvm]# cd /usr/lib/jvm
[root@preproduct1 /usr/lib/jvm]# cd java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/
[root@preproduct1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64]# source /etc/profile
[root@preproduct1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
6. 愉快的玩耍了
jstack pid > /home/appuser/msg.log
[Linux上使用yum安装openjdk] https://www.cnblogs.com/cailijuan/p/11899464.html