关于运维:Linux系统之安装java开发环境

4次阅读

共计 5485 个字符,预计需要花费 14 分钟才能阅读完成。

@TOC

一、java 介绍

1.java 简介

1.Java 是由 Sun Microsystems 公司于 1995 年 5 月推出的 Java 面向对象程序设计语言和 Java 平台的总称。由 James Gosling 和共事们独特研发,并在 1995 年正式推出,起初 Sun 公司被 Oracle(甲骨文)公司收买,Java 也随之成为 Oracle 公司的产品。
2.Java 是一种通用的,基于类的,面向对象的编程语言。它是用于利用程序开发的计算平台。因而,Java 是疾速,平安和牢靠的。

2.java 的三大平台

  • Java SE:Java 语言的(标准版),用于桌面利用的开发,是其余两个版本的根底。
  • Java ME:Java 语言的(小型版),用于嵌入式消费类电子设备(根本淘汰)。
  • Java EE:Java 语言的(企业版),用于 Web 方向的网站开发。

3.java 的次要个性

  • Java 语言是简略的
  • Java 语言是面向对象的
  • Java 语言是分布式的
  • Java 语言是强壮的
  • Java 语言是体系结构中立的
  • Java 语言是平安的
  • Java 语言是可移植的
  • Java 语言是解释型的
  • Java 是高性能的
  • Java 语言是多线程的
  • Java 语言是动静的

二、查看本地零碎环境

1. 查看零碎版本

查看本地零碎版本,本次实际应用的是 centos7.6 版本。

[root@jeven ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

2. 查看零碎内核版本

查看零碎内核版本

[root@jeven ~]# uname -r 
6.1.8-1.el7.elrepo.x86_64

三、清空 java 环境

1. 删除 java 目录

查问 java 所在位置

[root@jeven ~]# which java
/usr/bin/java

删除 java

[root@jeven ~]# rm -rf /usr/bin/java
[root@jeven ~]# java -version
bash: java: command not found...

2. 移除所有 java 相干包

卸载所有 java 相干的软件

 yum -y remove *java*

3. 清空 java 环境变量

在 /etc/profile 等环境变量文件中,删除 java 相干环境变量。

四、应用 yum 装置 java

1. 搜寻本地 java 软件版本

查看 java 是否装置

[root@jeven ~]# rpm -qa | grep java
[root@jeven ~]# 

搜寻 java 的 jdk 版本

[root@jeven ~]# yum list | grep java-1.8.0-openjdk
java-1.8.0-openjdk.i686                  1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk.x86_64                1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-accessibility.i686    1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-accessibility.x86_64  1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-demo.i686             1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-demo.x86_64           1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-devel.i686            1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-devel.x86_64          1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-headless.i686         1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-headless.x86_64       1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-javadoc.noarch        1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-javadoc-zip.noarch    1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-src.i686              1:1.8.0.362.b08-1.el7_9       updates  
java-1.8.0-openjdk-src.x86_64            1:1.8.0.362.b08-1.el7_9       updates  

2. 装置 java

装置的版本为 java-1.8.0-openjdk-devel.x86_64

yum install java-1.8.0-openjdk-devel.x86_64 -y

3. 配置环境变量

在 etc/profile 中配置 java 环境

AVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64/
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

使 java 相干变量失效

[root@jeven ~]# source /etc/profile
[root@jeven ~]# 

4. 查看 java 版本

查看 java 版本

[root@jeven lib]# java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (build 25.362-b08, mixed mode)
[root@jeven lib]# javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method parameters
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -h <directory>             Specify where to place generated native header files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -profile <profile>         Check that API used is available in the specified profile
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @<filename>                Read options and filenames from file

五、二进制包装置 java

1. 下载 java 软件包

java 下载地址:https://www.oracle.com/java/technologies/downloads/#java8

[root@jeven jdk]# ls
jdk-8u202-linux-x64.tar.gz

2. 解压 jdk 安装包

解压 jkd 软件的压缩包

[root@jeven jdk]# tar -xzf jdk-8u202-linux-x64.tar.gz 
[root@jeven jdk]# ls jdk
jdk1.8.0_202/               jdk-8u202-linux-x64.tar.gz  
[root@jeven jdk]# ls jdk1.8.0_202/
bin        include         jre  LICENSE  README.html  src.zip                             THIRDPARTYLICENSEREADME.txt
COPYRIGHT  javafx-src.zip  lib  man      release      THIRDPARTYLICENSEREADME-JAVAFX.txt

3. 复制 jdk 的二进制文件

将 jdk 的二进制文件复制到 /usr/local/ 目录下

[root@jeven ~]# cp -r /data/jdk/jdk1.8.0_202/ /usr/local/jdk/
[root@jeven ~]# ls /usr/local/jdk/
bin        include         jre  LICENSE  README.html  src.zip                             THIRDPARTYLICENSEREADME.txt
COPYRIGHT  javafx-src.zip  lib  man      release      THIRDPARTYLICENSEREADME-JAVAFX.txt

4. 配置环境变量

在 /etc/profile 文件中,新增以下两行:

export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin

使变量文件失效

source /etc/profile

5. 查看 java 版本

查看 java 版本,查看是否装置胜利。

[root@jeven ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

六、测试 java 装置环境

1. 编辑 test.java 文件

[root@jeven jdk]# cat test.java 
public class test{public static void  main (String[] args) {System.out.println("java test ok");
    }
}
[root@jeven jdk]# 

2. 运行测试文件

运行测试文件,查看是否正确输入,失常输入打印内容,则 java 环境装置胜利。

[root@jeven jdk]# javac test.java 
[root@jeven jdk]# java test
java test ok
正文完
 0