In this case, you need to put environment variables and java environment variables in the /root/.bashrc file. Note that this file is hidden. By default, you need to execute ls -a to display it.
#jdk
export JAVA_HOME=/lib/jvm
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
# User specific aliases and functions
You can see that when configuring environment variables, you need to configure them in the above way. This configuration file
Then, after each startup, the environment variable will automatically take effect