1. 下载sdk包。
官方下载:http://www.oracle.com/technetwork/java/javase/downloads/index.html
如下载目录~/download/jdk-6u37-linux-x64.bin
2. 解压:
chmod +x jdk-6u37-linux-x64.bin
./jdk-6u37-linux-x64.bin
3.创建java目录
sudo mkdir /usr/lib/jvm/
mv jdk1.6.0_37/ /usr/lib/jvm/sun-java6-jdk
4.配置
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/sun-java6-jdk/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/sun-java6-jdk/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/sun-java6-jdk/bin/javaws" 1
sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/sun-java6-jdk/bin/jar" 1
sudo update-alternatives --config java
#选择sun的java
5.修改环境变量:
sudo vim /etc/environment
export JAVA_HOME=/usr/lib/jvm/sun-java6-jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${JAVA_HOME}/bin"
sudo vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/sun-java6-jdk
export JRE_HOME=${JAVA_HOME}/jre
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:${PATH}
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
6.source /etc/profile
source /etc/environment
7.check java version
java -version