Oracle Java Archive
Linux下java Hello World!
直接下载解压,进入bin目录,简单测试,不需要配置任何环境变量:
chunli@linux:~/java$ tar xf jdk-8u101-linux-x64.gzchunli@linux:~$ cd jdk1.8.0_101/bin/chunli@linux:~/java/jdk1.8.0_101/bin$ cat java.java class HelloWorld { public static void main(String[]agrs) { System.out.println("HelloWorld!"); }}chunli@linux:~/java/jdk1.8.0_101/bin$ ./javac java.java chunli@linux:~/java/jdk1.8.0_101/bin$ ./java HelloWorld HelloWorld!chunli@linux:~/java/jdk1.8.0_101/bin$
JAVA 的hello world 出现!
临时设置环境变量
chunli@linux:~$ PATH=$PATH:/home/chunli/java/jdk1.8.0_101/bin/chunli@linux:~$ java -helpUsage: 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: Warning: this feature is deprecated and will be removed in a future release. require the specified version to run -showversion print product version and continue -jre-restrict-search | -no-jre-restrict-search Warning: this feature is deprecated and will be removed in a future release. 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 with specified granularity -da[: ...|: ] -disableassertions[: ...|: ] disable assertions with specified granularity -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 p_w_picpathSee http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.chunli@linux:~$ chunli@linux:~$ javac -helpUsage: javac
环境变量的永久设置
chunli@linux:~$ cdchunli@linux:~$ echo 'export PATH=$PATH:/home/chunli/java/jdk1.8.0_101/bin/' >> ./.profilechunli@linux:~$ tail ./.profile if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fifi# set PATH so it includes user's private bin if it existsif [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH"fiexport PATH=$PATH:/home/chunli/java/jdk1.8.0_101/bin/chunli@linux:~$ . ./.profilechunli@linux:~$ 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-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: Warning: this feature is deprecated and will be removed in a future release. require the specified version to run -showversion print product version and continue -jre-restrict-search | -no-jre-restrict-search Warning: this feature is deprecated and will be removed in a future release. 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 with specified granularity -da[: ...|: ] -disableassertions[: ...|: ] disable assertions with specified granularity -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 p_w_picpathSee http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.chunli@linux:~$