您的位置:首页 > 运维架构 > Linux

Linux系统下JDK安装,Java环境变量配置

2014-09-24 13:46 1266 查看
Linux系统安装JDK

  1、准备JDK安装文件,同样可以在Sun官网进行下载,下载前选择好相应的系统版本,可以下载bin文件也可以下载rpm包文件。我这里安装 "jdk-1_6_0_17-linux-i586.bin" 此版本。

  2、登陆Linux服务器(建议使用root用户,可使用SSH工具操作Linux,SSH工具的File Transfer上传文件),上传文件至服务器目录,如:"/home/appuser/"。

  3、将文件复制到需要安装的目录之下。命令:

  cp /home/appuser/jdk-1_6_0_17-linux-i586.bin /usr/local/jdk-1_6_0_17-linux-i586.bin


  4、到JDK所在目录(cd /usr/local/),赋予 jdk-1_6_0_17-linux-i586.bin 文件可执行权限。命令:

  chmod 777 jdk-1_6_0_17-linux-i586.bin


  5、执行文件,安装JDK。命令:

  ./jdk-1_6_0_17-linux-i586.bin


  6、同意Sun协议,完成安装,会生成目录 "jdk1.6.0_17"。若没有错误,到此则JDK安装完成。可以使用命令(mv jdk1.6.0_17 jdk)将该目录名更改为你需要的,例如 "jdk"。

四、Linux系统Java环境变量配置

  1、/etc/profile 文件就是Linux系统配置文件,为保险起见,先备份系统配置文件(cp /etc/profile /etc/profile-bak)。

  2、进入/etc/目录(cd /etc/)使用vi工具编辑profile文件(使用 vi profile 命令进入编辑器命令模式,输入"i"开始插入内容,将光标移动至目标位置,输入完毕之后按Esc退出编辑模式回到命令模式,命令模式下输入":wq!"保存退出),在末尾输入如下内容(Linux系统中的分隔符为":"):

  export JAVA_HOME=/usr/local/jdk
  export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

  export PATH=$JAVA_HOME/bin


  3、保存完毕之后使配置生效,命令:

  source /etc/profile


  4、验证版本

appuser@usm:~> java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)
appuser@usm:~>


appuser@usm:~> 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 | -jre-no-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
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-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
appuser@usm:~>


appuser@usm:~> 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

appuser@usm:~>


  至此Linux系统下JDK安装,Java环境变量配置全部完成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: