Linux下自定义安装JDK

自定义安装JDK

1、下载jdk安装包的几种方式

(1)通过浏览器把安装包下载到安装目录下(如:/usr/local/software):
官网地址:https://www.oracle.com/technetwork/java/javase/downloads/index.html
jdk8下载地址:https://download.oracle.com/otn-pub/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-linux-x64.tar.gz

(2)进入到安装目录下,执行 wget命令

注: 使用wget命令必须添加 “--no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" ”,否则无法下载ls

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-linux-x64.tar.gz
--2019-04-03 00:13:56--  https://download.oracle.com/otn-pub/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-linux-x64.tar.gz

(3)进入到安装目录下,执行 curl命令

2、解压安装包

进入到安装包下载目录下,执行如下命令:

tar -zxvf jdk-8u202-linux-x64.tar.gz

3、配置环境变量

(1)打开配置文件:

vim /etc/profile

(2)修改 profile 文件,添加如下内容:

# centos
# export JAVA_HOME=/usr/local/software/jdk1.8.0_202
# export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# export PATH=$PATH:$JAVA_HOME/bin

# JDK
export JAVA_HOME=/usr/local/software/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=${JAVA_HOME}/bin:$PATH

# Maven
export M2_HOME=/usr/local/software/maven
export MAVEN_HOME=/usr/local/software/maven
export PATH=${M2_HOME}/bin:$PATH
export PATH=${MAVEN_HOME}/bin:$PATH

(3)保存并退出配置文件修改操作

按"Esc"退出编辑,输入 ":wq!"保存且退出

(4)让配置文件立即生效

source /etc/profile

4、查看jDK版本

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)

你可能感兴趣的:(Linux下自定义安装JDK)