第一步,下载JDK
到 Oracle 官网下载jdk-6u45-linux-i586.bin
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html
第二步,解压安装
chmod 755 jdk-6u43-linux-i586.bin
./jdk-6u43-linux-i586.bin(注意,这个步骤一定要在jdk-6u11-linux-i586.bin所在目录下) 自解压
把解压好的文件放到你想安装的目录下面(我这是 /usr/lib/jvm/java下 放jdk1.6.0_45)
第三步,修改环境变量
gedit /etc/environment
修改(增加):
-
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
-
JAVA_HOME=/usr/lib/jvm/java/jdk1.6.0_45
-
JRE_HOME=${JAVA_HOME}/jre
-
CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
-
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
-
JAVA_HOME=/usr/lib/jvm/java/jdk1.6.0_43
-
JRE_HOME=${JAVA_HOME}/jre
-
CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
然后重新加载.bashrc
第四步,修改默认配置项
-
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_45/bin/java 300
-
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_45/bin/javac 300
-
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java/jdk1.6.0_45/bin/jar 300
-
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java/jdk1.6.0_45/bin/javah 300
-
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java/jdk1.6.0_45/bin/javap 300
-
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_43/bin/java 300
-
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_43/bin/javac 300
-
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java/jdk1.6.0_43/bin/jar 300
-
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java/jdk1.6.0_43/bin/javah 300
-
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java/jdk1.6.0_43/bin/javap 300
--这个不加的话最后用java -version检测出来的还是OpenJAVA。
sudo update-alternatives --config java
第五步,测试一下
-
without@without-pc:~/Downloads$ java -version
-
java version "1.6.0_45"
-
Java(TM) SE Runtime Environment (build 1.6.0_45-b01)
-
Java HotSpot(TM) Server VM (build 20.14-b01, mixed mode)
-
(责任编辑:IT) |