命令如下
新建文件夹-解压
sudo mkdir /home/njl/upload
进入upload目录
sudo tar zxvf jdk-7u79-linux-x64.tar
sudo tar zxvf jdk-7u79-linux-x64.tar
设置环境变量
sudo vim /etc/profile
加入环境变量内容
#set java environment
export JAVA_HOME=/home/njl/upload/jdk1.7(文件名称全名)
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export JAVA_HOME=/home/njl/upload/jdk1.7(文件名称全名)
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
设置默认的JDK
sudo update-alternatives --install /usr/bin/java java/home/njl/upload/jdk1.7/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /home/njl/upload/jdk1.7/bin/javac 300
sudo update-alternatives --install /usr/bin/javac javac /home/njl/upload/jdk1.7/bin/javac 300
然后运行一下这个命令
sudo update-alternatives --config java
测试
java -version
显示JDK版本则配置成功
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)