博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows、Linux系统安装JDK配置Java环境变量
阅读量:6862 次
发布时间:2019-06-26

本文共 8954 字,大约阅读时间需要 29 分钟。

一、Windows系统安装JDK

  1、准备JDK安装程序,可到Sun官网  下载需要的版本 (注意,32位系统选择X86;64位系统选择X64)。我这里安装 "jdk-6u23-windows-i586.exe"。

 

  2、双击运行 jdk-6u23-windows-i586.exe 程序,同意Sun协议,选择安装目录,JDK目录: C:\Java\jdk1.6.0_23;JRE目录 C:\Java\Jre (根据情况自己定),下一步直到完成,退出重启系统。

 

二、Windows系统Java环境变量配置

  1、准备参数

  我的JDK安装路径为 "C:\Java\jdk1.6.0_23" ,建议此路径不包含空格、目录层次不要太深;具体根据机器情况确定。

  定义系统环境变量:

  JAVA_HOME = C:\Java\jdk1.6.0_23   CLASSPATH = .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tool.jar   Path = %JAVA_HOME%\bin;

  注意:

    1) JAVA_HOME 指定 JDK 安装路径,该目录下有 "bin"、"jre"、"lib" 等子目录。很容易错写成 "C:\Java\jdk1.6.0_23\" ,请不要在 JDK 安装路径最后添加 "\"。

    2) CLASSPATH 使用系统变量 JAVA_HOME 作为参数(用%JAVA_HOME%表示),一般就按照上面的配置填写就行。需要注意在最前端有一个 "." 表示当前目录,并用 ";" 分隔。

    3) Path 需在系统原先配置的基础上增加 Java 环境的配置,指向 JDK 的 "bin" 目录,路径最后不要加 "\"。与系统其他配置值之间用 ";" 分隔。

 

  2、配置步骤

  1. Windows XP/Windows 2003

    桌面 ----(右击"我的电脑", 点击"属性")----> 系统属性 ----(点击"高级"选项卡, 点击"环境变量")----> 环境变量 ----(下面的系统变量, 点击"新建..."或选中点击"编辑")----> 填写变量名和变量值 ----(点击所有的"确定"保存更改)----> 完成

  2. Windows7

    桌面 ----(右击"计算机", 点击"属性")----> 控制面板\系统和安全\系统 ----(点击"高级系统设置")----> 系统属性 ----(点击"高级"选项卡, 点击"环境变量")----> 环境变量 ----(下面的系统变量, 点击"新建..."或选中点击"编辑")----> 填写变量名和变量值 ----(点击所有的"确定"保存更改)----> 完成

 

  3、版本验证

  运行 "cmd" 打开Dos命令行;可先输入 "java -version" 命令;再输入 "java" 命令;输入 "javac" 命令。如下:

C:\Users\Lilibo>java -version java version "1.6.0_23" Java(TM) SE Runtime Environment (build 1.6.0_23-b05) Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

 

C:\Users\Lilibo>java Usage: java [-options] class [args...]            (to execute a class)    or  java [-options] -jar jarfile [args...]            (to execute a jar file) where options include: -client       to select the "client" VM -server       to select the "server" VM -hotspot      is a synonym for the "client" VM  [deprecated]                   The default VM is client. -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 | -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[:
...|:
] -enableassertions[:
...|:
] enable assertions -da[:
...|:
] -disableassertions[:
...|:
] disable assertions -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

 

C:\Users\Lilibo>javac 用法:javac 
<选项>
<源文件>
其中,可能的选项包括: -g 生成所有调试信息 -g:none 不生成任何调试信息 -g:{lines,vars,source} 只生成某些调试信息 -nowarn 不生成任何警告 -verbose 输出有关编译器正在执行的操作的消息 -deprecation 输出使用已过时的 API 的源位置 -classpath
<路径>
指定查找用户类文件和注释处理程序的位置 -cp
<路径>
指定查找用户类文件和注释处理程序的位置 -sourcepath
<路径>
指定查找输入源文件的位置 -bootclasspath
<路径>
覆盖引导类文件的位置 -extdirs
<目录>
覆盖安装的扩展目录的位置 -endorseddirs
<目录>
覆盖签名的标准路径的位置 -proc:{none,only} 控制是否执行注释处理和/或编译。 -processor
[,
,
...]要运行的注释处理程序的名称;绕过默认 的搜索进程 -processorpath
<路径>
指定查找注释处理程序的位置 -d
<目录>
指定存放生成的类文件的位置 -s
<目录>
指定存放生成的源文件的位置 -implicit:{none,class} 指定是否为隐式引用文件生成类文件 -encoding
<编码>
指定源文件使用的字符编码 -source
<版本>
提供与指定版本的源兼容性 -target
<版本>
生成特定 VM 版本的类文件 -version 版本信息 -help 输出标准选项的提要 -Akey[=value] 传递给注释处理程序的选项 -X 输出非标准选项的提要 -J
<标志>
直接将
<标志>
传递给运行时系统 C:\Users\Lilibo>

 

  由此可见,安装配置的 JDK 环境正常,版本显示为 java version "1.6.0_23" 和环境变量配置一致。到此Windows环境变量配置完成。

 

三、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 
-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 | -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[:
...|:
] -enableassertions[:
...|:
] enable assertions -da[:
...|:
] -disableassertions[:
...|:
] disable assertions -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 appuser@usm:~>

 

appuser@usm:~> javac Usage: javac 
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
Specify where to find user class files and annotation processors -cp
Specify where to find user class files and annotation processors -sourcepath
Specify where to find input source files -bootclasspath
Override location of bootstrap class files -extdirs
Override location of installed extensions -endorseddirs
Override location of endorsed standards path -proc:{none,only} Control whether annotation processing and/or compilation is done. -processor
[,
,
...]Names of the annotation processors to run; bypasses default discovery process -processorpath
Specify where to find annotation processors -d
Specify where to place generated class files -s
Specify where to place generated source files -implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files -encoding
Specify character encoding used by source files -source
Provide source compatibility with specified release -target
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
Pass
directly to the runtime system appuser@usm:~>

  至此,Windows、Linux系统下JDK安装,Java环境变量配置全部完成。

 

转载于:https://www.cnblogs.com/lioillioil/archive/2011/09/14/2176595.html

你可能感兴趣的文章
Redis 过期淘汰策略
查看>>
运维自动化之puppet基础应用解析(经典版)
查看>>
最新版 WordPress 3.6 “Oscar” 简体中文版介绍及下载
查看>>
golang slice 和 array的区别
查看>>
SSDT Hook的妙用-对抗ring0 inline hook
查看>>
zabbix安装和使用
查看>>
SUSE Login incorrect
查看>>
批量备份脚本
查看>>
安全尽职是企业的阿克琉斯之踵
查看>>
Apache Qpid深入介绍
查看>>
java中获得对象构造器及其构造器参数类型
查看>>
TCP/IP 2.2配置静态路由
查看>>
一个在用的Log日志工具
查看>>
mutt msmtp 邮件发送功能
查看>>
hdfs fsck命令查看HDFS文件对应的文件块信息(Block)和位置信息
查看>>
roger vivier 12 31 One flats Could not offer an excepted
查看>>
saltstack 多master配置
查看>>
我的友情链接
查看>>
双主机hamcp的搭建(贴不了图,附件有详细文档可下载)
查看>>
表格table标签
查看>>