拷贝指定目录,安装jdk,事先建好文件夹jdk6
sudo cp jdk-6u45-linux-x64.bin /usr/lib/jvm/jdk6
cd /usr/lib/jvm/
sudo chmod 777 jdk6
sudo -s ./jdk6
修改环境变量配置文件
sudo vim /etc/profile
文件内追加如下内容
</pre><pre name="code" class="plain">JAVA_HOME=/usr/lib/jvm/jdk6
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
更新环境变量使配置生效
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java6/bin/java 300
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk6/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk6/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk6/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk6/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk6/bin/javap 300
sudo update-alternatives --config java
成功了
juanqiang@ubuntu:/usr/lib/jvm/jdk6$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
juanqiang@ubuntu:/usr/lib/jvm/jdk6$