0)到官网去下在jdk
wget http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz -O jdk-7-linux-x64.tar.gz
1)安装
tar -zxvf jdk-7-linux-x64.tar.gz
2)移动到指定目录,下面用软连接的原因是便于以后升级
mv jdk1.7.0 /Application/
ln -s /Application/jdk1.7.0 /Application/java
ln -s /Application/java/bin/java /sbin/java
3)设置环境变量
echo "export JAVA_HOME=/Application/java" > /etc/profile.d/java_env.sh echo "export JRE_HOME=/Application/java/jre" >> /etc/profile.d/java_env.sh
echo "export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH" >> /etc/profile.d/java_env.sh
echo "export PATH=.:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH" >> /etc/profile.d/java_env.sh
设置为可执行文件
chmod +x /etc/profile.d/java_env.sh
使环境变量在当前ssh客户端生效
source /etc/profile.d/java_env.sh
4)验证
最好把以前的java删除
root@vs-3310-099:/Application/java# java -version java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)
end
本文出自 “一方有” 博客,请务必保留此出处http://yifangyou.blog.51cto.com/900206/626559