Linux个人用户安装JDK(与root用户不同版本)

时间:2022-05-27 14:02:31

一、root用户安装JDK(1.7.0_40)

1.下载:JDK1.7.0_40下载路径

2.配置环境变量:

[root@localhost etc]# vim /etc/profile

添加如下内容到末尾:

   

   export JAVA_HOME='/usr/java/jdk1.7.0_40'
export JAVA_BIN='usr/java/jdk1.7.0_40/bin'
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export ES_JAVA_HOME='/home/slince/java/jdk1.8.0_131'
export JAVA_HOME JAVA_BIN CLASSPATH PATH ES_JAVA_HOME

然后保存退出(:wq)

3.刷新环境变量:

[root@localhost etc]# source /etc/profile

4.检查:

[root@localhost etc]# java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

二、个人用户安装JDK(1.8.0_131)

1.进入个人用户(slince,提前添加好的)

[root@localhost etc]# su - slince

2.下载:JDK1.8.0_131下载路径

3.配置环境变量:

[slince@localhost ~]$ vim .bashrc

添加如下内容到末尾:

export JAVA_HOME="/home/slince/java/jdk1.8.0_131"
export JRE_HOME=${JAVA_HOME}/jre
export PATH=${JAVA_HOME}/bin:$PATH
export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar

然后保存退出(:wq)

4.刷新环境变量:

[slince@localhost ~]$ source .bashrc

5.检查:

[slince@localhost ~]$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)