1.查找java相關得列表 [root@localhost ~]# yum -y list java* Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfilehtml
2.使用root用戶安裝 安裝時提醒必須使用root用戶,sudo都不行。 [root@localhost ~]# yum -y install java-1.7.0-openjdk* Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfilejava
Dependencies Resolvedshell
Installing: java-1.7.0-openjdk x86_64 1:1.7.0.79-2.5.5.1.el6_6 updates 26 M java-1.7.0-openjdk-demo x86_64 1:1.7.0.79-2.5.5.1.el6_6 updates 1.9 M java-1.7.0-openjdk-devel x86_64 1:1.7.0.79-2.5.5.1.el6_6 updates 9.4 M java-1.7.0-openjdk-javadoc noarch 1:1.7.0.79-2.5.5.1.el6_6 updates 16 M java-1.7.0-openjdk-src x86_64 1:1.7.0.79-2.5.5.1.el6_6 updates 39 M libjpeg-turbo x86_64 1.2.1-3.el6_5 base 174 k replacing libjpeg.x86_64 6b-46.el6bootstrap
Install 6 Package(s)centos
Total 143 kB/s | 92 MB 11:03
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Importing GPG key 0xC105B9DE: Userid : CentOS-6 Key (CentOS 6 Official Signing Key) centos-6-key@centos.org Package: centos-release-6-3.el6.centos.9.x86_64 (@base/$releasever) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : libjpeg-turbo-1.2.1-3.el6_5.x86_64 1/7 Installing : 1:java-1.7.0-openjdk-1.7.0.79-2.5.5.1.el6_6.x86_64 2/7 Installing : 1:java-1.7.0-openjdk-src-1.7.0.79-2.5.5.1.el6_6.x86_64 3/7 Installing : 1:java-1.7.0-openjdk-demo-1.7.0.79-2.5.5.1.el6_6.x86_64 4/7 Installing : 1:java-1.7.0-openjdk-devel-1.7.0.79-2.5.5.1.el6_6.x86_64 5/7 Installing : 1:java-1.7.0-openjdk-javadoc-1.7.0.79-2.5.5.1.el6_6.noarch 6/7 Erasing : libjpeg-6b-46.el6.x86_64 7/7 Verifying : 1:java-1.7.0-openjdk-src-1.7.0.79-2.5.5.1.el6_6.x86_64 1/7 Verifying : 1:java-1.7.0-openjdk-1.7.0.79-2.5.5.1.el6_6.x86_64 2/7 Verifying : 1:java-1.7.0-openjdk-javadoc-1.7.0.79-2.5.5.1.el6_6.noarch 3/7 Verifying : 1:java-1.7.0-openjdk-demo-1.7.0.79-2.5.5.1.el6_6.x86_64 4/7 Verifying : 1:java-1.7.0-openjdk-devel-1.7.0.79-2.5.5.1.el6_6.x86_64 5/7 Verifying : libjpeg-turbo-1.2.1-3.el6_5.x86_64 6/7 Verifying : libjpeg-6b-46.el6.x86_64 7/7oracle
Installed: java-1.7.0-openjdk.x86_64 1:1.7.0.79-2.5.5.1.el6_6
java-1.7.0-openjdk-demo.x86_64 1:1.7.0.79-2.5.5.1.el6_6
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.79-2.5.5.1.el6_6
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.79-2.5.5.1.el6_6
java-1.7.0-openjdk-src.x86_64 1:1.7.0.79-2.5.5.1.el6_6
libjpeg-turbo.x86_64 0:1.2.1-3.el6_5less
Replaced: libjpeg.x86_64 0:6b-46.el6jvm
Complete!ide
3.確認是否安裝成功ui
[root@localhost ~]# java -version java version "1.7.0_79" OpenJDK Runtime Environment (rhel-2.5.5.1.el6_6-x86_64 u79-b14) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode) [root@localhost ~]# javac Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:{lines,vars,source} Generate only some debugging info -nowarn Generate no warnings -verbose Output messages about what the compiler is doing -deprecation Output source locations where deprecated APIs are used -classpath <path> Specify where to find user class files and annotation processors -cp <path> Specify where to find user class files and annotation processors -sourcepath <path> Specify where to find input source files -bootclasspath <path> Override location of bootstrap class files -extdirs <dirs> Override location of installed extensions -endorseddirs <dirs> Override location of endorsed standards path -proc:{none,only} Control whether annotation processing and/or compilation is done. -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process -processorpath <path> Specify where to find annotation processors -d <directory> Specify where to place generated class files -s <directory> Specify where to place generated source files -implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files -encoding <encoding> Specify character encoding used by source files -source <release> Provide source compatibility with specified release -target <release> Generate class files for specific VM version -version Version information -help Print a synopsis of standard options -Akey[=value] Options to pass to annotation processors -X Print a synopsis of nonstandard options -J<flag> Pass <flag> directly to the runtime system -Werror Terminate compilation if warnings occur @<filename> Read options and filenames from file
[root@localhost ~]# 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 <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> A : separated list of directories, JAR archives, and ZIP archives to search for class files. -D<name>=<value> set a system property -verbose:[class|gc|jni] enable verbose output -version print product version and exit -version:<value> 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[:<packagename>...|:<classname>] -enableassertions[:<packagename>...|:<classname>] enable assertions with specified granularity -da[:<packagename>...|:<classname>] -disableassertions[:<packagename>...|:<classname>] disable assertions with specified granularity -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system assertions -agentlib:<libname>[=<options>] load native agent library <libname>, e.g. -agentlib:hprof see also, -agentlib:jdwp=help and -agentlib:hprof=help -agentpath:<pathname>[=<options>] load native agent library by full pathname -javaagent:<jarpath>[=<options>] load Java programming language agent, see java.lang.instrument -splash:<imagepath> show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
4.默認狀況下jdk安裝得路徑 /usr/lib/jvm 因爲咱們得機器可能同時安裝好幾個版本得jdk,因此在/etc/alternatives目錄下會有一個java連接到具體的java命令。而這個/etc/alternatives/java會被/usr/bin/java連接。從而java命令就被設置到了shell環境中。