Install and configure environment variables after uninstalling jdk in Linux
Under the Linux operating system of CentOS 7.x, there will be a built-in openjdk environment. If we want to install the jdk environment ourselves, we need to uninstall the built-in openjdk environment.
Proceed as follows:
1. View the java environment
java -version
2. Query jdk
# 查看linux的jdk
rpm -qa | grep jdk
3. Delete jdk
# 移除openjdk
yum -y remove java-openjdk-xxxxx
java-openjdk-xxxxx : is the openjdk that needs to be deleted
After deleting the built-in openjdk environment, we start to install our jdk.
4. Get the tarball from Windows or other machines
# 将文件传出Linux中的用户目录
scp D:/dsoftmanager/jdk-8u151-linux-x64.tar.gz root@192.168.108.5:/home/zhang
D:/dsoftmanager/jdk-8u151-linux-x64.tar.gz
: The location of the tar package directory of the A machine
[email protected]:/home/zhang
: The directory location where the linux machine stores the tar
5. Unzip the tar package to the specified directory
# 创建java目录
mkdir /usr/java
# 将文件复制到java目录
cp /home/zhang/jdk-8u151-linux-x64.tar.gz /usr/java
# 进入/usr/java
cd /usr/java
# 解压缩
tar -zxvf jdk-8u151-linux-x64.tar.gz
6. Configure environment variables
# 打开配置文件
vim /etc/profile
Open /etc/profile
the file, and at the end of the file, put the following configuration information:
# 配置java环境
JAVA_HOME=/usr/java/jdk1.8.0_151
PATH=$PATH:$JAVA_HOME/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export JAVA_HOME PATH CLASSPATH
7. Restart the machine
# 立即重启机器
shutdown -r now
If you do not restart, the configuration will not take effect.
8, java environment test
# 测试java环境是否安装成功
java -version
javac -version
The following information appears, indicating that the installation is successful.
[zhang@localhost Desktop]$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
[zhang@localhost Desktop]$ javac -version
javac 1.8.0_151