【记录】CentOS 6.6中安装Java

【背景】

折腾:

【记录】在CentOS 6.6中安装OpenFire

中,需要先去安装Java。

【折腾过程】

1.参考:

Install OpenFire 3.8.1 on CentOS 6.4 x86_64 – The Official Blog of Richard Ricketts

去操作:

[root@bogon ~]# yum search java
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * atomic: mirrors.hosting.in.th
 * base: mirrors.163.com
 * extras: mirrors.btte.net
 * updates: mirrors.163.com
======================================================== N/S Matched: java =========================================================
adaptx-javadoc.x86_64 : Javadoc for adaptx
ant-contrib-javadoc.noarch : Javadoc for ant-contrib
ant-javadoc.x86_64 : Javadoc for ant
ant-javamail.x86_64 : Optional javamail tasks for ant
antlr-javadoc.x86_64 : Javadoc for antlr
apache-jasper-javadoc.noarch : Javadoc for Jasper
avalon-framework-javadoc.x86_64 : Javadoc for avalon-framework
avalon-logkit-javadoc.noarch : Javadoc for avalon-logkit
axis-javadoc.noarch : Javadoc for axis
batik-javadoc.noarch : Javadoc for batik
bcel-javadoc.x86_64 : Javadoc for bcel
bea-stax-javadoc.x86_64 : Javadoc for bea-stax
brlapi-java.x86_64 : Java binding for BrlAPI
bsf-javadoc.noarch : Javadoc for bsf
bsh-javadoc.noarch : Javadoc for bsh
castor-javadoc.x86_64 : Javadoc for castor
classpathx-jaf-javadoc.x86_64 : Javadoc for classpathx-jaf
classpathx-mail-javadoc.noarch : Javadoc for classpathx-mail
db4-java.x86_64 : Development files for using the Berkeley DB (version 4) with Java
eclipse-mylyn-java.x86_64 : Mylyn Bridge:  Java Development
flute-javadoc.noarch : Javadoc for flute
fop-javadoc.x86_64 : Javadoc for fop
gcc-java.x86_64 : Java support for GCC
graphviz-java.x86_64 : Java extension for graphviz
hamcrest-javadoc.noarch : Javadoc for hamcrest
hsqldb-javadoc.noarch : Javadoc for hsqldb
icu4j-javadoc.x86_64 : Javadoc for icu4j
jakarta-commons-beanutils-javadoc.x86_64 : Javadoc for jakarta-commons-beanutils
jakarta-commons-codec-javadoc.x86_64 : Javadoc for jakarta-commons-codec
jakarta-commons-collections-javadoc.noarch : Javadoc for jakarta-commons-collections
jakarta-commons-collections-testframework-javadoc.noarch : Javadoc for jakarta-commons-collections-testframework
jakarta-commons-daemon-javadoc.x86_64 : Javadoc for jakarta-commons-daemon
jakarta-commons-dbcp-javadoc.noarch : Javadoc for jakarta-commons-dbcp
jakarta-commons-digester-javadoc.noarch : Javadoc for jakarta-commons-digester
jakarta-commons-discovery-javadoc.noarch : Javadoc for jakarta-commons-discovery
jakarta-commons-el-javadoc.noarch : Javadoc for jakarta-commons-el
jakarta-commons-httpclient-javadoc.x86_64 : Javadoc for jakarta-commons-httpclient
jakarta-commons-io-javadoc.noarch : Javadoc for jakarta-commons-io
jakarta-commons-lang-javadoc.noarch : Javadoc for jakarta-commons-lang
jakarta-commons-logging-javadoc.noarch : Javadoc for jakarta-commons-logging
jakarta-commons-net-javadoc.noarch : Javadoc for jakarta-commons-net
jakarta-commons-pool-javadoc.x86_64 : Javadoc for jakarta-commons-pool
jakarta-oro-javadoc.x86_64 : Javadoc for jakarta-oro
jakarta-taglibs-standard-javadoc.noarch : Javadoc for jakarta-taglibs-standard
java_cup.x86_64 : Java source interpreter
java_cup-javadoc.x86_64 : Javadoc for java_cup
java_cup-manual.x86_64 : Documentation for java_cup
javacc.x86_64 : A parser/scanner generator for java
javacc-demo.x86_64 : Examples for javacc
javacc-manual.x86_64 : Manual for javacc
javassist.noarch : The Java Programming Assistant provides simple Java bytecode manipulation
javassist-javadoc.noarch : Javadocs for javassist
jcommon-serializer-javadoc.noarch : Javadoc for jcommon-serializer
jdepend-javadoc.noarch : Javadoc for jdepend
jdom-javadoc.noarch : Javadoc for jdom
jflex-javadoc.noarch : Javadoc for jflex
jlex-javadoc.x86_64 : Javadoc for jlex
jna-javadoc.x86_64 : Javadocs for jna
jsch-javadoc.noarch : Javadoc for jsch
jss-javadoc.x86_64 : Java Security Services (JSS) Javadocs
jtidy-javadoc.noarch : Javadoc for jtidy
junit-javadoc.x86_64 : Javadoc for junit
junit4-javadoc.noarch : Javadoc for junit4
jython-javadoc.x86_64 : Javadoc for jython
jzlib-javadoc.x86_64 : Javadoc for jzlib
ldapjdk-javadoc.x86_64 : Javadoc for ldapjdk
libbase-javadoc.noarch : Javadoc for libbase
libfonts-javadoc.noarch : Javadoc for libfonts
libformula-javadoc.noarch : Javadoc for libformula
libguestfs-java.x86_64 : Java bindings for libguestfs
libguestfs-java-devel.x86_64 : Java development package for libguestfs
libguestfs-javadoc.x86_64 : Java documentation for libguestfs
liblayout-javadoc.noarch : Javadoc for liblayout
libloader-javadoc.noarch : Javadoc for libloader
libreadline-java.x86_64 : Java wrapper for the EditLine library
libreadline-java-javadoc.x86_64 : Javadoc for libreadline-java
libreoffice-javafilter.x86_64 : Optional javafilter module for LibreOffice
librepository-javadoc.noarch : Javadoc for librepository
libvirt-java.noarch : Java bindings for the libvirt virtualization API
libvirt-java-devel.noarch : Compressed Java source files for libvirt-java
libvirt-java-javadoc.noarch : Java documentation for libvirt-java
log4j-javadoc.x86_64 : Javadoc for log4j
lpg-java.noarch : Java runtime library for LPG
lpg-java-compat.noarch : Compatibility Java runtime library for LPG 1.x
lucene-javadoc.noarch : Javadoc for Lucene
mx4j-javadoc.noarch : Javadoc for mx4j
objectweb-anttask-javadoc.noarch : Javadoc for objectweb-anttask
objectweb-asm-javadoc.noarch : Javadoc for objectweb-asm
pentaho-libxml-javadoc.noarch : Javadoc for pentaho-libxml
pentaho-reporting-flow-engine-javadoc.noarch : Javadoc for pentaho-reporting-flow-engine
pki-common-javadoc.noarch : Certificate System - PKI Common Framework Javadocs
pki-java-tools.noarch : Certificate System - PKI Java-Based Tools
pki-java-tools-javadoc.noarch : Certificate System - PKI Java-Based Tools Javadocs
pki-util-javadoc.noarch : Certificate System - PKI Utility Framework Javadocs
ppl-java.x86_64 : The Java interface of the Parma Polyhedra Library
ppl-java-javadoc.x86_64 : Javadocs for ppl-java
qdox-javadoc.noarch : Javadoc for qdox
regexp-javadoc.x86_64 : Javadoc for regexp
rhino-javadoc.noarch : Javadoc for rhino
rome-javadoc.noarch : Javadocs for rome
sac-javadoc.noarch : Javadoc for sac
saxon-javadoc.noarch : Javadoc for saxon
sblim-cim-client-javadoc.noarch : Javadoc for sblim-cim-client
sblim-cim-client2-javadoc.noarch : Javadoc for sblim-cim-client2
setools-libs-java.i686 : Java bindings for SELinux policy analysis
setools-libs-java.x86_64 : Java bindings for SELinux policy analysis
slf4j-javadoc.noarch : Javadoc for slf4j
svnkit-javadoc.x86_64 : Javadoc for SVNKit
tagsoup-javadoc.noarch : Javadoc for tagsoup
tomcat6-javadoc.x86_64 : Javadoc generated documentation for Apache Tomcat
trilead-ssh2-javadoc.noarch : Javadoc for trilead-ssh2
tzdata-java.noarch : Timezone data for Java
velocity-javadoc.noarch : Javadoc for velocity
werken-xpath-javadoc.noarch : Javadoc for werken-xpath
ws-commons-util-javadoc.noarch : Javadoc for ws-commons-util
ws-jaxme-javadoc.noarch : Javadoc for ws-jaxme
wsdl4j-javadoc.noarch : Javadoc for wsdl4j
xalan-j2-javadoc.noarch : Javadoc for xalan-j2
xdoclet-javadoc.noarch : XDoclet Javadoc
xerces-j2-javadoc-apis.x86_64 : Javadoc for xerces-j2 apis
xerces-j2-javadoc-impl.x86_64 : Javadoc for xerces-j2 implementation
xerces-j2-javadoc-other.x86_64 : Javadoc for other xerces-j2 components
xerces-j2-javadoc-xni.x86_64 : Javadoc for xerces-j2 xni
xjavadoc.noarch : The XJavaDoc engine
xjavadoc-javadoc.noarch : Javadoc for xjavadoc
xml-commons-apis-javadoc.x86_64 : Javadoc for xml-commons-apis
xml-commons-resolver-javadoc.x86_64 : Javadoc for xml-commons-resolver
xmldb-api-javadoc.noarch : Javadoc for xmldb-api
xmlgraphics-commons-javadoc.noarch : Javadoc for xmlgraphics-commons
xmlrpc3-javadoc.noarch : Javadoc for xmlrpc3
zabbix-java-gateway.x86_64 : Zabbix java gateway
ant.x86_64 : Ant build tool for java
avalon-framework.x86_64 : Java components interfaces
avalon-logkit.noarch : Java logging toolkit
axis.noarch : A SOAP implementation in Java
batik.x86_64 : Scalable Vector Graphics for Java
bsh.noarch : Lightweight Scripting for Java
byaccj.x86_64 : Parser Generator with Java Extension
castor.x86_64 : An open source data binding framework for Java
classpathx-jaf.x86_64 : GNU JavaBeans(tm) Activation Framework
classpathx-mail.noarch : GNU JavaMail(tm)
ecj.x86_64 : Eclipse Compiler for Java
eclipse-jdt.x86_64 : Eclipse Java Development Tools
flute.x86_64 : Java CSS parser using SAC
gcc.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
gdb.x86_64 : A GNU source-level debugger for C, C++, Java and other languages
icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser plug-in and Web Start implementation
icedtea-web-javadoc.noarch : API documentation for IcedTea-Web
icu4j.x86_64 : International Components for Unicode for Java
jakarta-commons-collections.noarch : Provides new interfaces, implementations and utilities for Java Collections
jakarta-commons-daemon-jsvc.x86_64 : Java daemon launcher
jakarta-commons-lang.noarch : Provides a host of helper utilities for the java.lang API
jakarta-commons-net.noarch : Internet protocol suite Java library
java-1.5.0-gcj.x86_64 : JPackage runtime compatibility layer for GCJ
java-1.5.0-gcj-devel.x86_64 : JPackage development compatibility layer for GCJ
java-1.5.0-gcj-javadoc.x86_64 : API documentation for libgcj
java-1.5.0-gcj-src.x86_64 : Source files for libgcj
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
jcommon-serializer.x86_64 : JFree Java General Serialization Framework
jdepend.noarch : Java Design Quality Metrics
jdom.noarch : Java alternative to DOM and SAX
jlex.x86_64 : A Lexical Analyzer Generator for Java
jline.noarch : Java library for reading and editing user input in console applications
jna.x86_64 : Pure Java access to native libraries
jsch.noarch : Pure Java implementation of SSH2
jss.x86_64 : Java Security Services (JSS)
junit.x86_64 : Java regression test package
junit4.noarch : Java regression test package
jython.x86_64 : A Java implementation of the Python language
jzlib.x86_64 : JZlib re-implementation of zlib in pure Java
ldapjdk.x86_64 : The Mozilla LDAP Java SDK
libgcj.i686 : Java runtime library for gcc
libgcj.x86_64 : Java runtime library for gcc
libgcj-devel.i686 : Libraries for Java development using GCC
libgcj-devel.x86_64 : Libraries for Java development using GCC
libgcj-src.x86_64 : Java library sources from GCC4 preview
libreoffice-rhino.x86_64 : JavaScript support for LibreOffice
log4j.x86_64 : Java logging package
mx4j.noarch : Open source implementation of JMX Java API
mysql-connector-java.noarch : Official JDBC driver for MySQL
nuxwdog-client-java.x86_64 : Nuxwdog Watchdog client JNI Package
oprofile-jit.i686 : Libraries required for profiling Java and other JITed code
oprofile-jit.x86_64 : Libraries required for profiling Java and other JITed code
perl-JSON.noarch : Parse and convert to JSON (JavaScript Object Notation)
pl-jpl.x86_64 : A bidirectional Prolog/Java interface for SWI Prolog
rhino.noarch : JavaScript for Java
sac.x86_64 : Java standard interface for CSS parser
sat4j.noarch : A library of SAT solvers written in Java
saxon.noarch : Java XSLT processor
saxon-aelfred.noarch : Java XML parser
sblim-cim-client.noarch : Java CIM Client library
sblim-cim-client2.noarch : Java CIM Client library
sinjdoc.x86_64 : Documentation generator for Java source code
slf4j.noarch : Simple Logging Facade for Java
subversion-javahl.i686 : JNI bindings to the Subversion libraries
subversion-javahl.x86_64 : JNI bindings to the Subversion libraries
svnkit.x86_64 : Pure Java Subversion client library
tagsoup.noarch : A SAX-compliant HTML parser written in Java
tigervnc-server-applet.noarch : Java TigerVNC viewer applet for TigerVNC server
trilead-ssh2.noarch : SSH-2 protocol implementation in pure Java
v8.x86_64 : JavaScript Engine
velocity.noarch : Java-based template engine
wsdl4j.noarch : Web Services Description Language Toolkit for Java
xalan-j2.noarch : Java XSLT processor
xerces-j2.x86_64 : Java XML parser
xmldb-api.noarch : XML:DB API for Java

  Name and summary matches only, use "search all" for everything.
[root@bogon ~]# yum install java
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * atomic: mirrors.hosting.in.th
 * base: mirrors.163.com
 * extras: mirrors.btte.net
 * updates: mirrors.163.com
Package 1:java-1.7.0-openjdk-1.7.0.79-2.5.5.3.el6_6.x86_64 already installed and latest version
Nothing to do
[root@bogon ~]# 

结果显示已经安装过了java 1.7。

2.然后就是:

要搞清楚,如何确定已经安装了java:

[root@bogon ~]# java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.3.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
[root@bogon ~]# 

安装的是OpenJDK。

3.然后再去参考:

CentOS 64位 安装openfire | 在这里-迦楠的后花园

保证Java环境变量已经设置。

搜:

centos 6 install java

参考:

How To Install Java on CentOS and Fedora | DigitalOcean

How to Install JAVA 7 (JDK 7u79) on CentOS/RHEL 7/6/5

算了,直接去安装最新的java 1.8吧:

[root@bogon ~]# yum install java-1.8.0-openjdk-devel.x86_64
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * atomic: mirrors.hosting.in.th
 * base: mirrors.163.com
 * extras: mirrors.btte.net
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.45-28.b13.el6_6 will be installed
--> Processing Dependency: java-1.8.0-openjdk = 1:1.8.0.45-28.b13.el6_6 for package: 1:java-1.8.0-openjdk-devel-1.8.0.45-28.b13.el6_6.x86_64
--> Processing Dependency: libawt_xawt.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-devel-1.8.0.45-28.b13.el6_6.x86_64
--> Processing Dependency: libawt_xawt.so()(64bit) for package: 1:java-1.8.0-openjdk-devel-1.8.0.45-28.b13.el6_6.x86_64
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.45-28.b13.el6_6 will be installed
--> Processing Dependency: java-1.8.0-openjdk-headless = 1:1.8.0.45-28.b13.el6_6 for package: 1:java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64
--> Running transaction check
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.45-28.b13.el6_6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                                   Arch                 Version                                 Repository     Size
====================================================================================================================================
Installing:
 java-1.8.0-openjdk-devel                  x86_64               1:1.8.0.45-28.b13.el6_6                 updates                10 M
Installing for dependencies:
 java-1.8.0-openjdk                        x86_64               1:1.8.0.45-28.b13.el6_6                 updates               187 k
 java-1.8.0-openjdk-headless               x86_64               1:1.8.0.45-28.b13.el6_6                 updates                32 M

Transaction Summary
====================================================================================================================================
Install       3 Package(s)

Total download size: 42 M
Installed size: 142 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64.rpm                                               | 187 kB     00:00     
(2/3): java-1.8.0-openjdk-devel-1.8.0.45-28.b13.el6_6.x86_64.rpm                                     |  10 MB     00:15     
(3/3): java-1.8.0-openjdk-headless-1.8.0.45-28.b13.el6_6.x86_64.rpm                               |  32 MB     00:55     
------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                               599 kB/s |  42 MB     01:11     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64                                         1/3 
  Installing : 1:java-1.8.0-openjdk-headless-1.8.0.45-28.b13.el6_6.x86_64                         2/3 
  Installing : 1:java-1.8.0-openjdk-devel-1.8.0.45-28.b13.el6_6.x86_64                               3/3 
  Verifying  : 1:java-1.8.0-openjdk-devel-1.8.0.45-28.b13.el6_6.x86_64                              1/3 
  Verifying  : 1:java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64                                         2/3 
  Verifying  : 1:java-1.8.0-openjdk-headless-1.8.0.45-28.b13.el6_6.x86_64                         3/3 

Installed:
  java-1.8.0-openjdk-devel.x86_64 1:1.8.0.45-28.b13.el6_6                                                 

Dependency Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.45-28.b13.el6_6            java-1.8.0-openjdk-headless.x86_64 1:1.8.0.45-28.b13.el6_6           

Complete!

然后再去确认java的版本,结果还是1.7的:

[root@bogon ~]# java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.3.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

 

4.终于找到对应的java在哪里了:

[root@bogon ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@bogon ~]# ls /usr/lib/jvm
jvm/         jvm-commmon/ jvm-exports/ jvm-private/ 
[root@bogon ~]# ls /usr/lib/jvm
jvm/         jvm-commmon/ jvm-exports/ jvm-private/ 
[root@bogon ~]# ls /usr/lib/jvm/j
java/                                            jre-1.5.0/
java-1.5.0-gcj-1.5.0.0/                          jre-1.5.0-gcj/
java-1.7.0/                                      jre-1.7.0/
java-1.7.0-openjdk-1.7.0.79.x86_64/              jre-1.7.0-openjdk.x86_64/
java-1.7.0-openjdk.x86_64/                       jre-1.8.0/
java-1.8.0/                                      jre-1.8.0-openjdk/
java-1.8.0-openjdk/                              jre-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64/
java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64/ jre-gcj/
java-openjdk/                                    jre-openjdk/
jre/                                             
[root@bogon ~]# ls /usr/lib/jvm/java-
java-1.5.0-gcj-1.5.0.0/                          java-1.8.0/
java-1.7.0/                                      java-1.8.0-openjdk/
java-1.7.0-openjdk-1.7.0.79.x86_64/              java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64/
java-1.7.0-openjdk.x86_64/                       java-openjdk/
[root@bogon ~]# ls /usr/lib/jvm/java-1.
java-1.5.0-gcj-1.5.0.0/                          java-1.8.0/
java-1.7.0/                                      java-1.8.0-openjdk/
java-1.7.0-openjdk-1.7.0.79.x86_64/              java-1.8.0-openjdk-1.8.0.45-28.b13.el6_6.x86_64/
java-1.7.0-openjdk.x86_64/                       
[root@bogon ~]# ls /usr/lib/jvm/java-1.7.0-openjdk
java-1.7.0-openjdk-1.7.0.79.x86_64/ java-1.7.0-openjdk.x86_64/          
[root@bogon ~]# ls /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/
ASSEMBLY_EXCEPTION  bin  demo  include  jre  lib  LICENSE  sample  src.zip  tapset  THIRD_PARTY_README
[root@bogon ~]# 

重新配置环境变量,还是用,相对较流行的1.7的java吧(不用最新的1.8的java了):

[root@bogon ~]# vi ~/.bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

".bashrc" 17L, 368C written
[root@bogon ~]# source ~/.bashrc 
[root@bogon ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/bin
[root@bogon ~]# java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.3.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

 

【总结】

此处的CentOS 6中,默认已经安装了Java 1.7了,可通过:

java –version

去查看当前已安装的java版本。

然后也可以根据自己需要,去安装其他不同的版本,比如:

通过:

yum search java

找到很多不同版本:

java-1.5.0-gcj.x86_64 : JPackage runtime compatibility layer for GCJ
java-1.5.0-gcj-devel.x86_64 : JPackage development compatibility layer for GCJ
java-1.5.0-gcj-javadoc.x86_64 : API documentation for libgcj
java-1.5.0-gcj-src.x86_64 : Source files for libgcj
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle

根据需要,去安装自己想要的版本。

比如:

yum install java-1.8.0-openjdk-devel.x86_64

然后,在安装完毕之后,再去设置对应的java的环境变量:

vi ~/.bashrc

添加对应的配置。此处还是使用默认安装的1.7版本的java:

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

可以根据自己的需求,把路径换成其他对应不同版本,即可。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量