在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 ~]#