Windows、Linux系统安装JDK配置Java环境变量
一、Windows系統安裝JDK
1、準備JDK安裝程序,可到Sun官網?http://www.oracle.com/technetwork/java/javaee/downloads/index.html?下載需要的版本 (注意,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_23CLASSPATH = .;%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 -versionjava 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>javaUsage: 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 <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
?
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 <class1>[,<class2>,<class3>...]要運行的注釋處理程序的名稱;繞過默認
的搜索進程
-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/jdkexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin
?
3、保存完畢之后使配置生效,命令:
source /etc/profile?
4、驗證版本
appuser@usm:~> java -versionjava 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:~> javaUsage: 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:~> javacUsage: 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:~>
至此,Windows、Linux系統下JDK安裝,Java環境變量配置全部完成。
?
轉載于:https://www.cnblogs.com/lioillioil/archive/2011/09/14/2176595.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的Windows、Linux系统安装JDK配置Java环境变量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: winform datagridview
- 下一篇: 一些常用的CSS hack代码