CentOS, Debian, Ubuntu installation and configuration Java JDK environment

Introduction

JDK (Java Development Kit) is a software development kit (SDK) for the Java language.
Without JDK, Java programs (referring to java source code.java files) cannot be compiled. If you want to run only Java programs (referring to class or jar or other archive files), make sure that the corresponding JRE has been installed.

Download environment pack

download link

Orcal official website download

How to choose an environment package?

1. First check the current Linux distribution through lsb_release -a
insert image description here
insert image description here
2. Check the CPU architecture

root@deb01:~# uname -m
x86_64

3. Select the appropriate environment package according to the release version and CPU architecture
// The package managers supported by different release versions are different, and different architectures are not compatible. Download the environment package that suits you according to the previous steps
insert image description here

Installation Tutorial

tar.gz package installation

Centos, Debian, Ubuntu this method is common

Preparation

1. Upload the downloaded environment package to your Linux system
2. Create a directory to store the decompressed files

mkdir /usr/lib/java

3. Unzip the downloaded environment package to the created folder

tar -zxvf jdk-8u381-linux-x64.tar.gz -C /usr/lib/java/

4. Obtain the absolute path of the environment package
a) View the file structure in the java folder

[root@lolita java]# ls /usr/lib/java
jdk1.8.0_381

b) Enter jdk1.8.0_381 and get the absolute path

[root@lolita java]# cd /usr/lib/java/jdk1.8.0_381/
[root@lolita jdk1.8.0_381]# pwd
/usr/lib/java/jdk1.8.0_381		//这个就是绝对路径
Configure environment variables

5. Edit the configuration file /etc/profile to add at the end of the file

vim /etc/profile
export JAVA_HOME=/usr/lib/java/jdk1.8.0_381	 		//这里是你获取的jdk绝对路径
export JRE_HOME=$JAVA_HOME/jre			//配置jre路径
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/rt.jar 
//classpath是javac编译器专用的一个环境变量,作用是告诉Java执行环境,在哪些目录下可以找到您所要执行的Java程序所需要的类或者包。
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin      //定义环境变量

6. Refresh the environment variables to make the environment variables take effect immediately

 source /etc/profile

7. Detection and verification

java -version
java
javac
echo $JAVA_HOME

The above command does not report an error, and the Java environment is installed and configured.

Guess you like

Origin blog.csdn.net/shoujoai/article/details/132279340