Linux下安装JDK

通过rpm包安装

步骤:

1、从华为开源镜像网站中下载jdk的rpm包

2、在当前用户home目录下新建一个downloadfile,用来保存rpm包

1
[mutong@localhost ~]$ mkdir downloadfile

3、利用xftp将rpm包从Windows传输到Linux中的downloadfile目录下

4、在/usr/local目录下新建一个目录java/jdk,用来保存安装的jdk

1
[mutong@localhost local]$ mkdir -p java/jdk

5、rpm命令进行安装:

1
[mutong@localhost ~]$ sudo rpm -ivh --prefix=/usr/local/java/jdk jdk-8u202-linux-x64.rpm

6、配置环境变量

1
2
3
4
5
6
7
8
[mutong@localhost ~]$ vim /etc/profile
# /etc/profile
# jdk环境

JAVA_HOME=/usr/local/java/jdk/jdk1.8.0_202-amd64
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

7、重新加载配置文件

1
[mutong@localhost ~]$ source /etc/profile

8、测试是否安装成功

1
2
3
4
[mutong@localhost ~]$ 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)
------------- End -------------