一、Linux环境下安装教程
1.1 普通安装方式
官网:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
1.1.1 将下载好的压缩文件通过共享,或者Xshell工具上传到Linux系统;
1.1.2 将压缩文件解压到指定文件夹:
tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/local/jdk
1.1.3 配置JAVA_HOME,在/etc/profile文件的末尾加上
export JAVA_HOME=/usr/local/java/jdk1.8.0_171/
export JRE_HOME=/usr/local/java/jdk1.8.0_171/jre
export PATH=$PATH:/usr/local/java/jdk1.8.0_171/bin
export CLASSPATH=./:/usr/local/java/jdk1.8.0_171/lib:/usr/local/java/jdk1.8.0_171/jre/lib
通过以下命令使修改后的文件生效source /etc/profile
检查命令java -version
java
javac
1.2 docker方式安装JDK
1、搜索jdk的docker镜像 docker search jdk
[root@VM_0_9_centos ~]# docker search jdk
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/primetoninc/jdk Oracle jdk 1.8, 1.7 18 [OK]
docker.io docker.io/codenvy/jdk8_maven3_tomcat8 JDK 8, Maven 3, Tomcat 8 9 [OK]
docker.io docker.io/ascdc/jdk8 jdk8 7 [OK]
docker.io docker.io/codenvy/jdk7_tomcat7 Dockerfile https://github.com/codenvy/dock... 7
docker.io docker.io/kdvolder/jdk8 6
2、拉取镜像 docker pull
kdvolder/jdk8
[root@VM_0_9_centos ~]# docker pull kdvolder/jdk8
Using default tag: latest
Trying to pull repository docker.io/kdvolder/jdk8 ...
latest: Pulling from docker.io/kdvolder/jdk8
50aff78429b1: Pull complete
f6d82e297bce: Pull complete
275abb2c8a6f: Pull complete
9f15a39356d6: Pull complete
fc0342a94c89: Pull complete
8fa98a855564: Pull complete
Digest: sha256:419d116314d545535b538fa0a3730836ab2505963e43412f25c70c3fd29bdff3
Status: Downloaded newer image for docker.io/kdvolder/jdk8:latest
3、启动 docker run -di --name=jdk1.8 kdvolder/jdk8
[root@VM_0_9_centos ~]# docker run -di --name=jdk1.8 kdvolder/jdk8
49f1157bfa71bf57f22375b6cc38f153bced7d0ba9074f0cdcdcf4560b779276
4、查看是否启动成功 docker ps
[root@VM_0_9_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
49f1157bfa71 kdvolder/jdk8 "/bin/sh -c /bin/bash" 42 seconds ago Up 42 seconds jdk1.8
5、查看版本 docker exec -it jdk1.8 /bin/bash
java -version
[root@VM_0_9_centos ~]# docker exec -it jdk1.8 /bin/bash
root@49f1157bfa71:/# java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)