CentOS7 安装与配置 jdk & Maven | Eddie'Blog
 CentOS7 安装与配置 jdk & Maven

CentOS7 安装与配置 jdk & Maven

eddie 597 2020-04-29

jdk & Maven & git

下载资源

  1. 系统下载 CentOS7
    http://mirrors.aliyun.com/centos/7/isos/x86_64/

  2. jdk-8u241
    链接:https://pan.baidu.com/s/1R9LPq_XFrRZ9nXEyvnX44g
    提取码:jqxt

  3. Maven
    链接:https://pan.baidu.com/s/1s5wRwZzG34XUJSy-CjsINQ
    提取码:y8ed

备注:只是为了方便学习而提供,建议从官网下载

检测历史安装

查看Linux自带的JDK是否已安装

java -version

查看JDK信息

rpm -qa | grep java

卸载(有几个卸载几个)

rpm -e --nodeps java-x.x.x-gcj-compat-x.x.x.x-xxjpp.xxx
rpm -e --nodeps java-x.x.x-openjdk-x.x.x.x-x.x.bxx.exx

解压安装

tar -zxvf jdk-8u241-linux-i586.tar.gz
mv jdk1.8.0_241/ java  && mv java /usr/local/

tar -zxf apache-maven-3.6.3-bin.tar.gz
mv apache-maven-3.6.3/ maven && mv maven /usr/local/

配置环境变量

安装完成后需要配置一下环境变量,编辑/etc/profile文件:

vim /etc/profile

在文件尾部添加如下配置:

#java
export JAVA_HOME=/usr/local/java
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
#export PATH=$PATH:${JAVA_HOME}/bin

#maven
export M2_HOME=/usr/local/maven

#path
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

source命令重新加载/etc/profile文件,使得修改后的内容在当前shell窗口有效:

source /etc/profile

检查是否成功

成功

[root@server jdk1.8.0_241]# java -version            
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) Client VM (build 25.241-b07, mixed mode)

失败

[root@serverjdk1.8.0_241]# java -version
-bash: /usr/local/jdk1.8.0_241/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

PS: 需要运行
yum install glibc.i686 -y

运行java时候 libgcc_s.so.1

java.lang.UnsatisfiedLinkError: /usr/local/java/jre/lib/i386/libfontmanager.so: libgcc_s.so.1: cannot open shared object file: No such file or directory
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1838)
        at java.lang.Runtime.loadLibrary0(Runtime.java:870)
        at java.lang.System.loadLibrary(System.java:1122)
        at sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:61)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32)
        at sun.font.SunFontManager$1.run(SunFontManager.java:339)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.SunFontManager.<clinit>(SunFontManager.java:335)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
        at java.awt.Font.getFont2D(Font.java:491)
        at java.awt.Font.getFamily(Font.java:1220)
        at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
        at java.awt.Font.getFamily(Font.java:1186)
        at java.awt.Font.toString(Font.java:1683)
        at hudson.util.ChartUtil.<clinit>(ChartUtil.java:260)
        at hudson.WebAppMain.contextInitialized(WebAppMain.java:192)

PS: 需要运行

yum install -y libgcc_s.so.1