CentOS下安装java并且设置为默认

(1)查看linux中自带的java


yum list installed | grep java


(2)卸载自带的openJDK

yum -y remove R-java R-java-devel java-1.7.0-openjdk.x86_64 java-1.7.0-openjdk-devel.x86_64 java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-headless.x86_64 tzdata-java.noarch


(3)解压jdk文件并且放置在/usr/local/java/jdk下面


tar -zxvf jdk-8u121-linux-i586.tar.gz
mv jdk1.8.0_121 jdk

cd /usr/local 

mkdir java

cd ~

mv jdk /usr/local/java/

cd /usr/local/java/


(4)配置环境变量

vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk
export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

source /etc/profile

(5) 设置默认的java


update-alternatives --remove-all "java"
update-alternatives --remove-all "javac"
update-alternatives --remove-all "javaws"


update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk/bin/java" 1
update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk/bin/javac" 1
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk/bin/javaws" 1


update-alternatives --set java /usr/local/java/jdk/bin/java
update-alternatives --set javac /usr/local/java/jdk/bin/javac
update-alternatives --set javaws /usr/local/java/jdk/bin/javaws

你可能感兴趣的:(通用语言--Java语言,Linux操作系统)