docker安装jdk
现需要新搭建一套Linux环境,现使用docker安装jdk;
环境: Alibaba Cloud Linux 3
1.查看本地是否安装java
# java -version
-bash: java: command not found
2.使用docker拉取jdk镜像
# docker pull kdvolder/jdk8 Using default tag: latest latest: Pulling from 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 kdvolder/jdk8:latest docker.io/kdvolder/jdk8:latest
3.查看镜像:
# docker images REPOSITORY TAG IMAGE ID CREATED SIZE kdvolder/jdk8 latest b83ae7c076b1 5 years ago 488MB
4.运行镜像
# docker run -itd --name=jdk1.8 kdvolder/jdk8 bash e93c8a419860cffb440e8fdfa1448f9775f80564d892f53da6ff3c063a59a828
5.查看镜像运行情况
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e93c8a419860 kdvolder/jdk8 "bash" About a minute ago Up About a minute jdk1.8
Linux本地安装jdk:
1.创建文件夹
mkdir /usr/local/java/ cd /usr/local/java/
2.下载并解压
wget https://mirrors.tuna.tsinghua.edu.cn/Adoptium/8/jdk/x64/linux/OpenJDK8U-jdk_x64_linux_hotspot_8u392b08.tar.gz ll tar -zxvf OpenJDK8U-jdk_x64_linux_hotspot_8u392b08.tar.gz
3.设置环境变量
# yum -y install nano Last metadata expiration check: 2:59:35 ago on Sun 10 Dec 2023 08:53:04 PM CST. Dependencies resolved. ==================================================================================================================================== Package Architecture Version Repository Size ==================================================================================================================================== Installing: nano x86_64 2.9.8-1.2.al8 alinux3-os 586 k Transaction Summary ==================================================================================================================================== Install 1 Package Total download size: 586 k Installed size: 2.3 M Downloading Packages: nano-2.9.8-1.2.al8.x86_64.rpm 11 MB/s | 586 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------ Total 11 MB/s | 586 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : nano-2.9.8-1.2.al8.x86_64 1/1 Running scriptlet: nano-2.9.8-1.2.al8.x86_64 1/1 Verifying : nano-2.9.8-1.2.al8.x86_64 1/1 Installed: nano-2.9.8-1.2.al8.x86_64 Complete!
4.编辑环境变量文件
nano /etc/profile
将如下内容写入文件末尾
export JAVA_HOME=/usr/local/java/jdk8u392-b08 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
应用环境变量,使之生效
]# source /etc/profile
5.设置软连接
# ln -sf /usr/local/java/jdk8u392-b08/bin/java /usr/bin/java
6.查看jdk版本,是否安装成功
# java -version openjdk version "1.8.0_392" OpenJDK Runtime Environment (Temurin)(build 1.8.0_392-b08) OpenJDK 64-Bit Server VM (Temurin)(build 25.392-b08, mixed mode)