现在在Centos7下搭建一下java开发环境,由于自带的java版本为1.7.0且升级到1.8.0后且不带javac等编译工具,所以我打算卸掉重新完整的装一次看能否解决问题.
[root@mycentos shell]# uname -a
Linux mycentos 3.10.0-327.36.2.el7.x86_64 #1 SMP Mon Oct 10 23:08:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
1.先用yum list installed |grep java 查看一下当前安装的JDK
[root@mycentos shell]# yum list installed |grep java
java-1.8.0-openjdk.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-accessibility-debug.x86_64
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-headless-debug.x86_64
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch
java-1.8.0-openjdk-src.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-atk-wrapper.x86_64 0.30.4-5.el7 @base
javapackages-tools.noarch 3.4.1-11.el7 @base
python-javapackages.noarch 3.4.1-11.el7 @anaconda
tzdata-java.noarch 2017a-1.el7 @updates
[root@mycentos shell]#
2. 卸载带有@updates标志的所有java组件.
[root@mycentos shell]# yum -y remove java-1.8.0-openjdk*
[root@mycentos shell]# yum -y remove tzdata-java.noarch
分别执行,如结果显示complete并没有任何报错,说明已经成功卸载.
3.确保网络正常情况,查看yum库中的java安装包
[root@mycentos shell]# yum -y list java*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.sohu.com
Installed Packages
javapackages-tools.noarch 3.4.1-11.el7 @base
Available Packages
java-1.6.0-openjdk.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-demo.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-devel.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-src.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-accessibility.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-demo.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-headless.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-src.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.8.0-openjdk.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-debug.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-atk-wrapper.i686 0.30.4-5.el7 base
java-atk-wrapper.x86_64 0.30.4-5.el7 base
java_cup.noarch 1:0.11a-16.el7 base
java_cup-javadoc.noarch 1:0.11a-16.el7 base
java_cup-manual.noarch 1:0.11a-16.el7 base
javacc.noarch 5.0-10.el7 base
javacc-demo.noarch 5.0-10.el7 base
javacc-javadoc.noarch 5.0-10.el7 base
javacc-manual.noarch 5.0-10.el7 base
javacc-maven-plugin.noarch 2.6-17.el7 base
javacc-maven-plugin-javadoc.noarch 2.6-17.el7 base
javamail.noarch 1.4.6-8.el7 base
javamail-javadoc.noarch 1.4.6-8.el7 base
javassist.noarch 3.16.1-10.el7 base
javassist-javadoc.noarch 3.16.1-10.el7 base
4. 执行安装java-1.8.0-openjdk所有包,大约有18个包(16个+2个依赖包),需要个几分钟时间(网速和镜像资源相关)
[root@mycentos shell]# yum -y install java-1.8.0-openjdk*
同样结果显示complete并没有任何报错,说明已经成功安装.
[root@mycentos shell]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@mycentos shell]# javac
Usage: javac
查看javac显示用法,说明正常,图中标黄是最常用到编译选项,顺便附上这个命令用法的中文版
[root@mycentos Desktop]# javac
用法: javac
下面用vim编辑器,写两个小程序HelloWord.java和HelloString.java,并编译生产.class的字节码文件,然后执行给出结果.
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello, World!");
}
}
public class HelloString{
static String s1="你好!";
public static void main(String[] args){
String s2="java";
System.out.println(s1);
System.out.println(s2);
}
}
后者主要使用成员变量和局部变量,打印输出.
使用通配符,使用javac命令一次性对上面两个文件进行编译.[root@mycentos shell]# javac -cp ./ Hello*.java
编译成功后注意同时生成的字节码文件
执行分别执行结果如下:
[root@mycentos shell]# java HelloWorld
Hello, World!
[root@mycentos shell]# java HelloString
你好!
java