Linux系统之安装java开发环境
Linux系统之安装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环境
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.402.b06-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_402" OpenJDK Runtime Environment (build 1.8.0_402.b06) 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