在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
執行安裝
再測試就行了
補充:Vi編輯常用快捷鍵
復制:ctrl+insert
粘貼:shift+insert
按Esc保存退出編譯,shift+zz退出
本文轉自:https://blog.csdn.net/yalecaltech/article/details/70158620
