在
linux
下编译
java
程序,执行
javac
编译生成
class
文件时,在
centos7
终端输入如,
javac hello.java
会
提示未找到指令,但用
java -verison
测试环境变量是没问题的
百度了好久,说的很复杂,重新再
linux
配置环境变量,输入
vi /etc/profile
进入,添加以下代码:
export JAVA_HOME=/usr/local/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
再测试,最后也没有成功
后来在
stackoverflow
上看到了这个
84 down vote accepted
You installed the Java Runtime Environment (JRE) only, which does not contain javac. For javac,
you have to install the OpenJDK Development Environment. You can install java-devel or java-
1.6.0-openjdk-devel, which both include javac.
By the way: you can find out which package provides javac with a yum search, e.g.
su -c 'yum provides javac'
Another note: using yum and openjdk is only one possibility to install the JDK. Many people prefer
Sun/Oracle's "original" SDK. See How to install Java SDK on CentOS? and links for alternatives.
大意就是我们用
yum
来装原生的就行了
在终端输入
yum install java-devel
执行安装
再测试就行了。