overview
服务器端运行Java程序,首先需要安装jdk,并设置环境变量。 接下来就来介绍一下如何在 Centos 7 系统中配置java环境变量
Create jdk installation directory
## 1、创建jdk安装目录
mkdir -p /usr/jdk/jdk20
Download OpenJDK 20
## 进入安装目录
cd /usr/jdk/jdk20
## 下载openjdk20
wget https://download.java.net/java/GA/jdk20.0.1/b4887098932d415489976708ad6d1a4b/9/GPL/openjdk-20.0.1_linux-x64_bin.tar.gz
Unzip JDK
tar xvf openjdk-20.0.1_linux-x64_bin.tar.gz.1 -C /usr/java/openjdk20/
Configure environment variables
vim /etc/profile
Add the following configuration at the end of the profile:
#java
export JAVA_HOME=/usr/java/openjdk20/jdk-20.0.1
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
#让配置生效
source /etc/profile
Create a soft connection for the command
After establishing a soft connection, the java and javac commands can be executed in other directories.
## 为java命令建立软连接
ln -s /usr/java/openjdk20/jdk-20.0.1/bin/java /usr/bin/java
## 为javac命令建立软连接
ln -s /usr/java/openjdk20/jdk-20.0.1/bin/javac /usr/bin/javac
Test whether the javag environment is configured successfully
## 查看java版本信息
java -verison
## java编译命令
javac
How to uninstall java
Use rpm -qa|grep jdk
or rpm -qa|grep java
to view the existing versions of the system
and use rpm -e --nodeps
+ name to uninstall them one by one.
Add WeChat account [Xiaosify] to join the group to open up the promotion management channel for programmers.