linux rhel8 安装java开发环境
1、系统版本、java环境查看
[root@linuxprobe home]# cat /etc/system-release ## 查看系统版本
Red Hat Enterprise Linux release 8.0 (Ootpa)
[root@linuxprobe home]# java ##没有java命令
bash: java: command not found...
Failed to search for file: Cannot update read-only repo
[root@linuxprobe home]# java -version ## 没有java版本信息
bash: java: command not found...
Failed to search for file: Cannot update read-only repo
[root@linuxprobe home]# which java ##未安装java
/usr/bin/which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@linuxprobe home]# rpm -qa | grep jdk ## 没有java
[root@linuxprobe home]# echo $JAVA_HOME ##没有java环境变量
2、下载最新版本java,下载地址:https://www.oracle.com/java/technologies/javase-jdk15-downloads.html,如下图:
[root@linuxprobe home]# uname -a ## 查看内核架构
Linux linuxprobe.com 4.18.0-80.el8.x86_64 #1 SMP Wed Mar 13 12:02:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@linuxprobe home]# hostnamectl ## 查看内核架构
Static hostname: linuxprobe.com
Icon name: computer-vm
Chassis: vm
Machine ID: 1667052376ea4207aa566e9d7a42456b
Boot ID: f05c4ad96bf5468a8f869ead700acc1a
Virtualization: vmware
Operating System: Red Hat Enterprise Linux 8.0 (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8.0:GA
Kernel: Linux 4.18.0-80.el8.x86_64
Architecture: x86-64
[root@linuxprobe local]# cd /usr/local ## 安装包下载至此目录
[root@linuxprobe local]# ls
bin etc games include lib lib64 libexec sbin share src
[root@linuxprobe local]# ls ## 在windows下载后上传,也可以直接在linux下载
bin etc games include jdk-15_linux-x64_bin.tar.gz lib lib64 libexec sbin share src
[root@linuxprobe local]#tar -xzvf jdk-15_linux-x64_bin.tar.gz ##解压
[root@linuxprobe local]# ls
bin etc games include jdk-15 jdk-15_linux-x64_bin.tar.gz lib lib64 libexec sbin share src
[root@linuxprobe local]# mv jdk-15_linux-x64_bin.tar.gz jdk-15 将安装移动至解压目录
[root@linuxprobe local]# mv jdk-15/ java ## 重命名,方便配置环境变量
3、配置环境变量
[root@linuxprobe local]# vim /etc/profile ## vim 打开配置文件 G ## 打开后输入大写G进入末行 o ## 然后输入小写0,在下一行开始编辑,输入以下以export开头的四行(配置环境变量) export JAVA_HOME=/usr/local/java export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JRE_HOME=$JAVA_HOME/jre
source /etc/profile ## 使环境变量生效
4、检测是否生效
[root@linuxprobe local]# java ## 直接在终端输入java
Usage: java [options] <mainclass> [args...]
(to execute a class)
or java [options] -jar <jarfile> [args...]
(to execute a jar file)
or java [options] -m <module>[/<mainclass>] [args...]
java [options] --module <module>[/<mainclass>] [args...] …………………………
[root@linuxprobe local]# java -version ## 可以查看到版本信息
java version "15" 2020-09-15
Java(TM) SE Runtime Environment (build 15+36-1562)
Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
[root@linuxprobe local]# which java ## 查找java命令
/usr/local/java/bin/java
[root@linuxprobe local]# rpm -qa | grep jdk ## 没有使用rpm包安装,因此查询不到
[root@linuxprobe local]# echo $JAVA_HOME ## 查询java环境变量
/usr/local/java
以上利用*tar.gz已经安装了java环境。
5、java环境的安装也可以使用rpm包来安装
参考:https://blog.csdn.net/u010993514/article/details/82926514