专栏首页运维前线CentOS 7 配置Java语言开发环境

CentOS 7 配置Java语言开发环境

CentOS 7 配置Java语言开发环境

初始化设置参考:http://blog.csdn.net/wh211212/article/details/52923673

安装JDK8

安装Java SE开发工具包8(JDK8)并构建Java环境

[root@linuxprobe ~]# curl -L "http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.rpm" -H "Cookie: oraclelicense=accept-securebackup-cookie"  -H "Connection: keep-alive" -O
# 采用yum或者rpm方式安裝jdk(這裡一yum為例)
[root@linuxprobe ~]# yum localinstall jdk-8u121-linux-x64.rpm -y
Loaded plugins: fastestmirror
Examining jdk-8u121-linux-x64.rpm: 2000:jdk1.8.0_121-1.8.0_121-fcs.x86_64
Marking jdk-8u121-linux-x64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.0_121.x86_64 2000:1.8.0_121-fcs will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================================================================================
 Package                                                         Arch                                                      Version                                                               Repository                                                               Size
===============================================================================================================================================================================================================================================================================
Installing:
 jdk1.8.0_121                                                    x86_64                                                    2000:1.8.0_121-fcs                                                    /jdk-8u121-linux-x64                                                    263 M

Transaction Summary
===============================================================================================================================================================================================================================================================================
Install  1 Package

Total size: 263 M
Installed size: 263 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2000:jdk1.8.0_121-1.8.0_121-fcs.x86_64                                                                                                                                                                                                                      1/1
Unpacking JAR files...
    tools.jar...
    plugin.jar...
    javaws.jar...
    deploy.jar...
    rt.jar...
    jsse.jar...
    charsets.jar...
    localedata.jar...
  Verifying  : 2000:jdk1.8.0_121-1.8.0_121-fcs.x86_64                                                                                                                                                                                                                      1/1

Installed:
  jdk1.8.0_121.x86_64 2000:1.8.0_121-fcs

Complete!
[root@linuxprobe ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
# 設置jdk環境變量
[root@linuxprobe ~]# vi /etc/profile
# add follows to the end
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
[root@linuxprobe ~]# source /etc/profile

参考链接:http://blog.csdn.net/gsls200808/article/details/52336745(使用curl和wget下载最新版JDK)

  • 如果安装了另一个版本的JDK,请更改默认值,如下所示:
# 以java-1.8.0-openjdk為例
[root@linuxprobe ~]# yum install java-1.8.0-openjdk -y
[root@linuxprobe ~]# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/java/jdk1.8.0_121/jre/bin/java
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64/jre/bin/java)
# 选择通过yum安装的最新版的Oracle JDK
Enter to keep the current selection[+], or type selection number: 1
  • 创建测试程序确保java环境正常
[root@linuxprobe ~]# vi day.java
 import java.util.Calendar;

class day {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DATE);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute);
    }
}

# compile
[root@linuxprobe ~]# javac day.java 
[root@linuxprobe ~]# java day
2017/4/12 21:49

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Mysql 常用命令

    版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。 https://blog...

    shaonbean
  • CentOS 7 minimal安装完成之后安装图形界面

    实验环境:CentOS 7 minimal ,hostname:linuxprobe.org IP:10.1.1.53

    shaonbean
  • 10.4 Git 内部原理 - 包文件

    让我们重新回到示例 Git 版本库的对象数据库。 目前为止,可以看到有 11 个对象——4 个数据对象、3 个树对象、3 个提交对象和 1 个标签对象:

    shaonbean
  • Web基础配置篇(一): Java环境配置

    href="https://jq.qq.com/?_wv=1027&k=52sgH1J"

    品茗IT
  • Jvm中各种内存溢出情况分析

    oom即OutOfMemoryError,出现这个报错的主要原因是内存空间不足以装下数据导致抛出异常。要探讨JVM出现oom的情况,首先要了解下jvm的内存模型...

    DH镔
  • 如何将CDH集群JAVA升级至JDK8

    大家都知道在安装CDH时默认安装的JDK版本为jdk1.7.0_67,部分企业开发环境为JDK8版本,这个时候可能会出现在本地开发的应用在集群中无法正常运行。那...

    Fayson
  • java字节码byte code简介

    Byte Code也叫做字节码,是连接java源代码和JVM的桥梁,源代码编译成为字节码,而字节码又被加载进JVM中运行。字节码怎么生成,怎么查看字节码,隐藏在...

    程序那些事
  • 【Hibernate那点事儿】—— Hibernate应该了解的知识

    前言: 最近由于有点时间,就像深入的学习一下Hibernate.之前只是简单的使用,并没领会它的妙处。这里就趁着分享的机会,好好整理一下。   这篇主要...

    用户1154259
  • 【Hibernate那点事儿】—— Hibernate应该了解的知识

    前言: 最近由于有点时间,就像深入的学习一下Hibernate.之前只是简单的使用,并没领会它的妙处。这里就趁着分享的机会,好好整理一下。   这篇主要...

    用户1154259
  • Redis也能搞定时任务,你们耗子尾汁

    码农小胖哥

扫码关注云+社区

领取腾讯云代金券