一:查看原来的jdk安装路径
[root@li1062-188 bin]# which java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64/bin/java
[root@li1062-188 bin]#
which java 是查看java的执行路径
二:卸载旧版本的jdk版本
1:查找jdk的版本在哪个路径
[root@li1062-188 bin]# rpm -qa | grep jdk
java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64
java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64
[root@li1062-188 bin]# rpm -qa | grep gcj (这个难道是垃圾加收机制吗)
libgcj-4.4.7-16.el6.x86_64
2:卸载jdk
[root@li1062-188 bin]# yum -y remove java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.101-2.6.6.1.el6_7 will be erased
--> Processing Dependency: java-1.7.0-openjdk = 1:1.7.0.101-2.6.6.1.el6_7 for package: 1:java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64
--> Running transaction check
---> Package java-1.7.0-openjdk-devel.x86_64 1:1.7.0.101-2.6.6.1.el6_7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================================
Removing:
java-1.7.0-openjdk x86_64 1:1.7.0.101-2.6.6.1.el6_7 @updates 91 M
Removing for dependencies:
java-1.7.0-openjdk-devel x86_64 1:1.7.0.101-2.6.6.1.el6_7 @updates 36 M
Transaction Summary
============================================================================================================================================================================================================================================
Remove 2 Package(s)
Installed size: 127 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : 1:java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64 1/2
Erasing : 1:java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64 2/2
Verifying : 1:java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64 1/2
Verifying : 1:java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64 2/2
Removed:
java-1.7.0-openjdk.x86_64 1:1.7.0.101-2.6.6.1.el6_7
Dependency Removed:
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.101-2.6.6.1.el6_7
Complete!
[root@li1062-188 bin]# yum -y remove java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64
Loaded plugins: fastestmirror
Setting up Remove Process
No Match for argument: java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Package(s) java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64 available, but not installed.
No Packages marked for removal
[root@li1062-188 bin]# rpm -qa | grep jdk
[root@li1062-188 bin]#
[root@li1062-188 bin]# rpm -qa | grep gcj
libgcj-4.4.7-16.el6.x86_64
[root@li1062-188 bin]# yum -y remove libgcj-4.4.7-16.el6.x86_64
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package libgcj.x86_64 0:4.4.7-16.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================================
Removing:
libgcj x86_64 4.4.7-16.el6 @base 62 M
Transaction Summary
============================================================================================================================================================================================================================================
Remove 1 Package(s)
Installed size: 62 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : libgcj-4.4.7-16.el6.x86_64 1/1
warning: /usr/lib64/security/classpath.security saved as /usr/lib64/security/classpath.security.rpmsave
Verifying : libgcj-4.4.7-16.el6.x86_64 1/1
Removed:
libgcj.x86_64 0:4.4.7-16.el6
Complete!
3.查看 /etc/profile 里面有没有配置java_home,安装完成之后,可以查看CLASSPATH,PATH等路径
[root@li1062-188 bin]# echo $JAVA_HOME
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
以上,就卸载掉了jdk
三:下载新的jdk文件,一是通过wget 方式,一是通过yum install jdk 的方式,当不知道wget的路径时候,我们采用第二种方法。
1:查看有哪些可以安装的jdk
[root@li1062-188 bin]# yum -y list java*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Available Packages
java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base
java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base
java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base
java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base
java-1.6.0-openjdk.x86_64 1:1.6.0.38-1.13.10.0.el6_7 updates
java-1.6.0-openjdk-demo.x86_64 1:1.6.0.38-1.13.10.0.el6_7 updates
java-1.6.0-openjdk-devel.x86_64 1:1.6.0.38-1.13.10.0.el6_7 updates
java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.38-1.13.10.0.el6_7 updates
java-1.6.0-openjdk-src.x86_64 1:1.6.0.38-1.13.10.0.el6_7 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.101-2.6.6.1.el6_7 updates
java-1.7.0-openjdk-demo.x86_64 1:1.7.0.101-2.6.6.1.el6_7 updates
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.101-2.6.6.1.el6_7 updates
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.101-2.6.6.1.el6_7 updates
java-1.7.0-openjdk-src.x86_64 1:1.7.0.101-2.6.6.1.el6_7 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.91-0.b14.el6_7 updates
java_cup.x86_64 1:0.10k-5.el6 base
java_cup-javadoc.x86_64 1:0.10k-5.el6 base
java_cup-manual.x86_64 1:0.10k-5.el6 base
javacc.x86_64 4.1-0.5.el6 base
javacc-demo.x86_64 4.1-0.5.el6 base
javacc-manual.x86_64 4.1-0.5.el6 base
javassist.noarch 3.9.0-6.el6 base
javassist-javadoc.noarch
2:下载并安装jdk1.7,注意我们需要下载两个文件,
java-1.7.0-openjdk.x86_64 只有jre
java-1.7.0-openjdk-devel.x86_64
[root@li1062-188 bin]# yum -y install java-1.7.0-openjdk.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.101-2.6.6.1.el6_7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================================
Installing:
java-1.7.0-openjdk x86_64 1:1.7.0.101-2.6.6.1.el6_7 updates 26 M
Transaction Summary
============================================================================================================================================================================================================================================
Install 1 Package(s)
Total download size: 26 M
Installed size: 91 M
Downloading Packages:
java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64.rpm | 26 MB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64 1/1
Verifying : 1:java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el6_7.x86_64 1/1
Installed:
java-1.7.0-openjdk.x86_64 1:1.7.0.101-2.6.6.1.el6_7
Complete!
[root@li1062-188 bin]# yum -y install java-1.7.0-openjdk-devel.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.7.0-openjdk-devel.x86_64 1:1.7.0.101-2.6.6.1.el6_7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================================
Installing:
java-1.7.0-openjdk-devel x86_64 1:1.7.0.101-2.6.6.1.el6_7 updates 9.4 M
Transaction Summary
============================================================================================================================================================================================================================================
Install 1 Package(s)
Total download size: 9.4 M
Installed size: 36 M
Downloading Packages:
java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64.rpm | 9.4 MB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64 1/1
Verifying : 1:java-1.7.0-openjdk-devel-1.7.0.101-2.6.6.1.el6_7.x86_64 1/1
Installed:
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.101-2.6.6.1.el6_7
Complete!
3:查看jdk 是否安装OK
[root@li1062-188 bin]# java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server.
-cp
-classpath
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D=
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:...|:]
-enableassertions[:...|:]
enable assertions with specified granularity
-da[:...|:]
-disableassertions[:...|:]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:[=]
load native agent library , e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:[=]
load native agent library by full pathname
-javaagent:[=]
load Java programming language agent, see java.lang.instrument
-splash:
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
[root@li1062-188 bin]# java -version
java version "1.7.0_101"
OpenJDK Runtime Environment (rhel-2.6.6.1.el6_7-x86_64 u101-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
四:配置jdk的环境变量
1:找到java的安装路径
[root@li1062-188 bin]# cd /
[root@li1062-188 /]# find -name java
./var/lib/alternatives/java
./etc/pki/ca-trust/extracted/java
./etc/pki/java
./etc/alternatives/java
./etc/java
./usr/share/java
./usr/bin/java
./usr/lib/jvm-exports/java
./usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64/jre/bin/java
./usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64/bin/java
./usr/lib/jvm/java
./usr/lib/java
或者
[root@li1062-188 /]# which java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64/bin/java
[root@li1062-188 /]#
2:在/etc/profile 中配置jdk环境变量
[root@li1062-188 /]# vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
3:上面就是安装jdk的全部过程了。