首先到官网下载 Linux x64 182.87 MB jdk-8u191-linux-x64.tar.gz
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载到一个目录下,然后用SecureCRT alt+p sftp> put D:/aasoftware/pinyougou/jdk-8u191-linux-x64.tar.gz 回车传输
通过终端在/usr/local目录下新建java文件夹,命令行:
sudo mkdir /usr/local/java
然后将下载到压缩包拷贝到java文件夹中,命令行:
进入jdk源码包所在目录
cp jdk-8u66-linux-x64.tar.gz /usr/local/java
然后进入java目录,命令行:
cd /usr/local/java
解压压缩包,命令行:
sudo tar zxvf jdk-8u66-linux-x64.tar.gz
然后可以把压缩包删除,命令行:
sudo rm jdk-8u66-linux-x64.tar.gz
3、设置jdk环境变量
这里采用全局设置方法,就是修改etc/profile,它是是所有用户的共用的环境变量
vi /etc/profile
打开之后在末尾添加
JAVA_HOME=/usr/local/java/jdk1.8.0_191 JRE_HOME=/usr/local/java/jdk1.8.0_191/jre CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$JAVA_HOME/bin:$PATH export PATH JAVA_HOME CLASSPATH
使环境变量生效
source /etc/profile
看看自己的配置是否都正确
echo $JAVA_HOME echo $CLASSPATH echo $PATH java -version
[root@localhost bin]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
查看已经安装的jdk
[root@bogon jre]# rpm -qa|grep jdk java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64 java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64 java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
卸载命令
[root@bogon jre]# yum -y remove java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
卸载完成之后Java命令不被识别
[root@bogon lib]# java -version bash: java: command not found...
致谢:
https://blog.csdn.net/weixin_30670925/article/details/97310163
转载于:https://www.cnblogs.com/duanwandao/p/9946085.html
相关资源:Linux下安装与卸载jdk_linux删除原来的jdk-其它代码类资源