Java教程

CentOS7安装JDK1.8

本文主要是介绍CentOS7安装JDK1.8,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

第一步,检查yum的更新

[root@bogon mnt]# yum update
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No packages marked for update

第二步下载jdk1.8

https://www.jb51.net/softs/551521.html#downintro2

上面是脚本之家里面的

第三步通过“Xftp 7”上传到mnt目录下

[root@bogon mnt]# ls
hgfs  jdk-linux-x64.tar.gz

第四步解压并重命名为jdk1.8,放入usr/local目录下

//解压
root@bogon mnt]# tar xzf jdk-linux-x64.tar.gz
[root@bogon mnt]# ls
hgfs  jdk1.8.0_131  jdk-linux-x64.tar.gz
//重命名
[root@bogon mnt]# mv jdk1.8.0_131 jdk1.8
[root@bogon mnt]# ls
hgfs  jdk1.8  jdk-linux-x64.tar.gz
//移动到 /usr/local下面
[root@bogon mnt]# mv jdk1.8 /usr/local
[root@bogon mnt]# ls
hgfs  jdk-linux-x64.tar.gz
[root@bogon mnt]# cd /usr/local
//查看是否在
[root@bogon local]# ls
bin  etc  games  include  jdk1.8  lib  lib64  libexec  sbin  share  src

 第五步

配置环境

[root@bogon local]# vi /etc/profile

添加以下代码

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

完成样式

//截取下部分
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}

第六步,

[root@bogon local]# source /etc/profile
[root@bogon local]# java -version

检查

[root@bogon bin]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

跑一跑springboot打包后的jar包

[root@bogon mnt]# ls
Hello.jar  hgfs  jdk-linux-x64.tar.gz
[root@bogon mnt]# java -jar Hello.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.0)

2021-12-02 12:27:34.733  WARN 43141 --- [           main] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 10036 milliseconds to respond. Please verify your network configuration.
2021-12-02 12:27:44.783  INFO 43141 --- [           main] com.wang.hello.HelloApplication          : Starting HelloApplication v0.0.1-SNAPSHOT using Java 1.8.0_131 on bogon with PID 43141 (/mnt/Hello.jar started by root in /mnt)
2021-12-02 12:27:44.784  INFO 43141 --- [           main] com.wang.hello.HelloApplication          : No active profile set, falling back to default profiles: default
2021-12-02 12:27:45.799  INFO 43141 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-12-02 12:27:45.812  INFO 43141 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-12-02 12:27:45.812  INFO 43141 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.55]
2021-12-02 12:27:45.867  INFO 43141 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-12-02 12:27:45.867  INFO 43141 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1038 ms
2021-12-02 12:27:46.165  INFO 43141 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-12-02 12:27:46.174  INFO 43141 --- [           main] com.wang.hello.HelloApplication          : Started HelloApplication in 47.078 seconds (JVM running for 47.443)
2021-12-02 12:28:52.914  INFO 43141 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-12-02 12:28:52.915  INFO 43141 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-12-02 12:28:52.916  INFO 43141 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms

这篇关于CentOS7安装JDK1.8的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!