1、查看Linux系统中是否安装了jdk:
java -version
2、卸载Java
大部分安装Java都是用rpm命令安装的,那么我们就要先用rpm -qa jdk 命令来查找Java的安装包
如上图,我们就找到了我们安装jdk的安装包,下面就来卸载jdk
使用语句:rpm -e jdk-1.7.0_75-fcs
这样jdk就卸载完成了
3.安装
下载jdk (1.8)
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
以上下载页面中找到下载链接(必须同意licence,并且链接过一段时间很失效)
http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm?AuthParam=1505267515_9a1d49d5008a9f270c9f4c19e08e4a5b
安装(指定安装目录)
mv jdk-8u144-linux-x64.rpm\?AuthParam\=1505267515_9a1d49d5008a9f270c9f4c19e08e4a5b jdk-8u144-linux-x64.rpm
rpm -ivh --prefix=/usr/local/java jdk-8u144-linux-x64.rpm
执行过程如下:
[root@iZwz9c99pok3qrsia9hZ ~]# rpm -ivh --prefix=/usr/local/java jdk-8u144-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk1.8.0_144 ########################################### [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
ln: creating symbolic link `/usr/java/jdk1.8.0_144': No such file or directory
drwxr-xr-x 9 root root 4096 Sep 13 09:54 jdk1.8.0_144
查看验证安装是否正确
[root@iZwz9c99pok3qrsia9hZ java]# cd /usr/local/java/
[root@iZwz9c99pok3qrsia9hZ java]# ls
jdk1.8.0_144
[root@iZwz9c99pok3qrsia9hZ java]# cd jdk1.8.0_144/bin/
[root@iZwz9c99pok3qrsia9hZ bin]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode
第四步:配置环境变量(全局)
vi /etc/profile
末尾添加
export JAVA_HOME=/usr/local/java/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
然后,按Esc键,再按 : 再输入 wq ,保存并退出,这样就配置好了,但是不会立即生效,需要你重新登录(或source /etc/profile),然后输入:java -version 命令