java安装配置-centos平台

在centos下,默认装的是openjdk的 jre版本。

可以使用java 但不能使用 javac

[root@superguy ~]# rpm -qa | grep jdk 
java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.4.el7_5.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64
java-1.8.0-openjdk-headless-1.8.0.181-3.b13.el7_5.x86_64
[root@superguy ~]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
[root@superguy ~]# javac
bash: javac: command not found...
Similar command is: 'java'
[root@superguy ~]# 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>
                  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[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -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
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
[root@superguy ~]#

后来查询发现需要装 openjdk 的devel 版本

[root@superguy ~]# yum list |grep jdk
copy-jdk-configs.noarch                  3.3-10.el7_5                   @updates
java-1.7.0-openjdk.x86_64                1:1.7.0.191-2.6.15.4.el7_5     @updates
java-1.7.0-openjdk-headless.x86_64       1:1.7.0.191-2.6.15.4.el7_5     @updates
java-1.8.0-openjdk.x86_64                1:1.8.0.191.b12-0.el7_5        @updates
java-1.8.0-openjdk-headless.x86_64       1:1.8.0.191.b12-0.el7_5        @updates
java-1.6.0-openjdk.x86_64                1:1.6.0.41-1.13.13.1.el7_3     base    
java-1.6.0-openjdk-demo.x86_64           1:1.6.0.41-1.13.13.1.el7_3     base    
java-1.6.0-openjdk-devel.x86_64          1:1.6.0.41-1.13.13.1.el7_3     base    
java-1.6.0-openjdk-javadoc.x86_64        1:1.6.0.41-1.13.13.1.el7_3     base    
java-1.6.0-openjdk-src.x86_64            1:1.6.0.41-1.13.13.1.el7_3     base    
java-1.7.0-openjdk-accessibility.x86_64  1:1.7.0.191-2.6.15.4.el7_5     updates 
java-1.7.0-openjdk-demo.x86_64           1:1.7.0.191-2.6.15.4.el7_5     updates 
java-1.7.0-openjdk-devel.x86_64          1:1.7.0.191-2.6.15.4.el7_5     updates 
java-1.7.0-openjdk-javadoc.noarch        1:1.7.0.191-2.6.15.4.el7_5     updates 
java-1.7.0-openjdk-src.x86_64            1:1.7.0.191-2.6.15.4.el7_5     updates 
java-1.8.0-openjdk.i686                  1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-accessibility.i686    1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-accessibility.x86_64  1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-accessibility-debug.i686
java-1.8.0-openjdk-accessibility-debug.x86_64
java-1.8.0-openjdk-debug.i686            1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-debug.x86_64          1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-demo.i686             1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-demo.x86_64           1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-demo-debug.i686       1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-demo-debug.x86_64     1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-devel.i686            1:1.8.0.191.b12-0.el7_5        updates 
java-1.8.0-openjdk-devel.x86_64          1:1.8.0.191.b12-0.el7_5        updates

先更新 openjdk的jre版本,然后下载最新的 openjdk的devel版本。这个版本可以运行 javac

yum install java-1.8.0-openjdk-devel


参考国外教程

一、Installing Java

Before installing Tomcat we will have to install Java Development Kit (JDK) on our system but it is recommended that you update the system and available packages before installing JDK. Run the following command to update system.

yum -y update

Now once the system is updated install JDK and to do so run following command:

yum -y install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64

The above command will take some time to install JDK so you should wait until the installation process has finished.

When Java is installed check the java version with the following command:

java -version

You’ll see a result similar to this :

[root@ip-172-31-16-36 ~]# java -version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-b15)
OpenJDK 64-Bit Server VM (build 25.111-b15, mixed mode)
[root@ip-172-31-16-36 ~]#

二、Java Home Environment

Before you configure Java Home Environment we recommend you to check where the Java directory is and to do so run following command:

sudo update-alternatives --config java

Now edit the environment file with any text editor here we are using nano editor but you can choose anyone you wish.

nano /etc/environment

Now add the Java Home Environment variable as shown below :

JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre"

You can simply copy/paste this to your file.

After adding Java Home Environment save and exit from the editor.

Now we’ll have to edit the .bash_profile so run the command given below:

nano ~/.bash_profile

Now add the Home Environment variable as shown below:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre export PATH=$JAVA_HOME/bin:$PATH

Save file and exit from the editor.

We recommend you reload the .bash_profile, to do so run following command:

source ~/.bash_profile

We recommend you make sure there is no error in configuring Home Environment variable and also check the Java Home environment variable :

echo $JAVA_HOME

You will see output similar to this containing the path to java directory :

[root@ip-172-31-16-36 ~]# nano ~/.bash_profile
[root@ip-172-31-16-36 ~]# source ~/.bash_profile
[root@ip-172-31-16-36 ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre
[root@ip-172-31-16-36 ~]#

 

java安装配置-配置环境变量

初学java的时候,最害怕的就是下载JDK后要配置环境变量了,关键是当时不理解,所以战战兢兢地照着书籍上或者是网络上的介绍进行操作。然后下次再弄的时候,又忘记了而且是必忘。当时,心里的想法很气愤的,想着是–这东西一点也不人性化,为什么非要自己配置环境变量呢?太不照顾菜鸟和新手了,很多菜鸟就是因为卡在环境变量的配置上,遭受了太多的挫败感。

一、Window平台
配置环境变量主要有3个:JAVA_HOME、PATH、CLASSPATH。

1、JAVA_HOME
指的是你JDK安装的位置,一般默认安装在C盘,如
C:\Program Files\Java\jdk1.8.0_91

2、PATH
将程序路径包含在PATH当中后,在命令行窗口就可以直接键入它的名字了,而不再需要键入它的全路径,比如上面代码中我用的到javac和java两个命令。
一般的PATH=%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%PATH%;
也就是在原来的PATH路径上添加JDK目录下的bin目录和jre目录的bin.

3、CLASSPATH(其实现在已经不需要配置了)
CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
一看就是指向jar包路径。
需要注意的是前面的.;,.代表当前目录。

如果用命令行进行编译运行时:
说明:网上有人说配置java开发环境时没必要在classpath添加dt.jar和tool.jar,编译时可以找到。classpath中只需放一些第三方或自己编写的jar包路径。classpath 变量的含义是告诉jvm要使用或执行的class放在什么路径上,便于JVM加载class文件。

环境变量的设置与查看
设置可以右击我的电脑,然后点击属性,再点击高级,然后点击环境变量,具体不明白的自行查阅文档。
查看的话可以打开命令行窗口

echo %JAVA_HOME%
echo %PATH%
echo %CLASSPATH%

二、mac平台:
mac 系统 默认自带了 jdk。
查看的话可以打开命令行窗口 。好像 没有看到 CLASSPATH 环境变量 。
echo $CLASSPATH 输出是空白

echo $JAVA_HOME
#结果显示 /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
echo $PATH
# 结果显示 /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/toy/Documents/maven/apache-maven-3.5.3/bin:/Library/Tomcat/my_script_diy:/Library/Tomcat/home/bin:/usr/local/mysql/bin:/Users/cool/Library/Android/sdk/platform-tools

查看java是否安装:

java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

java安装配置-安装版本选择

java 下载时,经常 会看到 有两个 版本:
比如
http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html

Java SE Development Kit 8u171
Java SE Development Kit 8u172

那我们究竟应该 下载 哪个版本 比较好呢。

简单来说,奇数版本 是修复了之前 的严重错误  的版本。经过了很多测试。
下一代奇数版本,将包括上一代偶数版本所修复的全部bug。

偶数版本,修复了之前严重错误 和 额外错误的版本。仍需要机构再多测试。

查看 网站讨论 链接:https://www.reddit.com/r/java/comments/8d3i9e/jdk_8u171_vs_jdk_8u172/?st=jhk8n1q9&sh=49328aa6

官方说明链接:
http://www.oracle.com/technetwork/java/javase/cpu-psu-explained-2331472.html

Java CPU and PSU Releases Explained

October 14, 2014

Starting with the release of Java SE 7 Update 71 (Java SE 7u71) in October 2014, Oracle will release a Critical Patch Update (CPU) at the same time as a corresponding Patch Set Update (PSU) for Java SE 7.


Which Java version should I choose: the CPU or the PSU?

Oracle strongly recommends that all Java SE users upgrade to the latest CPU release available for a release family. Most users should choose the CPU release.

Users should only use the corresponding PSU release if they are being impacted by one of the additional bugs fixed in that version as noted in the release notes.

The subsequent CPU release will contain all of the fixes from the current PSU. For this reason, organizations should test the current PSU in their environment in anticipation of these fixes being included in the next CPU.

What is the difference between a Java CPU and PSU release?

Java SE Critical Patch Updates (CPU) contain fixes to security vulnerabilities and critical bug fixes. Oracle strongly recommends that all Java SE users upgrade to the latest CPU releases as they are made available. Java SE CPU releases are odd numbered versions (i.e. 7u71, 7u65 – see more on Java SE version numbering schemes here).

Java SE Patch Set Updates (PSU) contain all of fixes in the corresponding CPU, as well as additional non-critical fixes. Java PSU releases should only be used if you are being impacted by one of the additional bugs fixed in that version. The release notes call out the additional fixes available in Java SE PSU releases.

Is the cadence of CPU releases changing?

As before, Java SE CPU releases are scheduled for release on the Tuesday closest to the 17th day of January, April, July and October under the normal Oracle Critical Patch Update schedule.

Starting in October 2014 with the release of Java SE 7u71 (CPU) and Java SE 7u72 (PSU), Oracle plans to additionally release a corresponding PSU release along with each CPU release for Java SE 7. PSU releases provide organizations and developers with access to non-critical fixes in addition to the critical fixes contained in the corresponding CPU.

Resources and Additional Information:

 


发布说明:release note
http://www.oracle.com/technetwork/java/javase/8u-relnotes-2225394.html

This page lists all the release notes for public releases and Bundled Patch Release (BPR) builds of JDK 8.

BPR builds are available only as commercial offerings to Oracle customers.

For a complete listing of release notes for all JDK 8 update releases in a single page, see Release Notes for JDK 8 and JDK 8 Update Releases. This page compiles information for many releases (loading this page through slow connections will take longer than loading release notes for individual releases).