linux 系统中如何安装java环境(通过tar.gz文件)

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   ## 查看版本
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]# 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: c37ae01cf99e40909900fa77495cca76
    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

 

2、下载最新java安装包 、安装

下载地址:https://www.oracle.com/java/technologies/javase-jdk15-downloads.html

 

 下载至:/home/software (可选)

[root@linuxprobe software]# ll -h
total 180M
-rw-r--r--. 1 root root 180M Oct 17 01:30 jdk-15_linux-x64_bin.tar.gz
[root@linuxprobe software]# pwd
/home/software
[root@linuxprobe software]# tar -xzvf jdk-15_linux-x64_bin.tar.gz  ## 解压
[root@linuxprobe software]# mv jdk-15_linux-x64_bin.tar.gz jdk-15  ## 将安装包移动至解压的文件夹
[root@linuxprobe software]# mv jdk-15/ java  ## 对文件夹进行重命名

[root@linuxprobe software]# cd java/bin/ ## 进入java程序的路径

[root@linuxprobe bin]# ls
jaotc java javap jdb jfr jinfo jmod jrunscript jstat rmid
jar javac jcmd jdeprscan jhsdb jlink jpackage jshell jstatd rmiregistry
jarsigner javadoc jconsole jdeps jimage jmap jps jstack keytool serialver
[root@linuxprobe bin]# pwd  ##输出当前路径
/home/software/java/bin
[root@linuxprobe bin]# echo $PATH  ## 显示路径环境变量
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@linuxprobe bin]# ln -s /home/software/java/bin/java /usr/bin/java  ## 在/usr/bin路径下建立java可执行程序的软链接,注意建立软链接一定要使用绝对路径

 

 

3、测试安装结果

[root@linuxprobe bin]# 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...]
           (to execute the main class in a module)
[root@linuxprobe bin]# 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 bin]# which java  ## 查看可执行程序
/usr/bin/java
[root@linuxprobe bin]# whoami
root
[root@linuxprobe bin]# su - linuxprobe  ## 切换至普通用户检测,没有问题
[linuxprobe@linuxprobe ~]$ whoami
linuxprobe
[linuxprobe@linuxprobe ~]$ 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...]
           (to execute the main class in a module)
[linuxprobe@linuxprobe ~]$ 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)
[linuxprobe@linuxprobe ~]$ which java
/usr/bin/java

 

4、卸载:删除建立的软链接、删除java的安装包


[linuxprobe@linuxprobe ~]$ su - root  ## 切换至root
Password:
[root@linuxprobe ~]# whoami
root


[root@linuxprobe ~]# rm -rf /usr/bin/java ## 删除软链接 [root@linuxprobe ~]# rm -rf /home/software/java ## 删除安装包 [root@linuxprobe ~]# java ## 检测卸载效果 bash: java: command not found... Failed to search for file: Cannot update read-only repo [root@linuxprobe ~]# java -version ##同上 bash: java: command not found... Failed to search for file: Cannot update read-only repo [root@linuxprobe ~]# which java ##同上 /usr/bin/which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

 

posted @ 2020-10-16 17:47  小鲨鱼2018  阅读(1574)  评论(0编辑  收藏  举报