常规方法 (推荐)
没网络但是有jdk.bin时,有网络时请忽略前5步
1.cd /usr
2.在usr目录下建立java安装目录
sudo mkdir java
3.将jdk-6u24-linux-i586.bin拷贝到java目录下
sudo cp /实际目录/jdk-6u24-linux-i586.bin /usr/java
4.安装jdk
sudo ./jdk-6u24-linux-i586.bin
5.安装完毕为他建立一个链接以节省目录长度
sudo ln -s /usr/java/jdk1.6.0_24/ /usr/jdk
有网络时,可不用以上步骤
直接sudo apt-get install sun-java6-jdk
之后需要设置默认的java程序
sudo update-alternatives --config java
按照提示输入对应的选项,指定为JDK 6
下面设置
sudo vim /etc/environment
在其中添加如下两行:
CLASSPATH=/usr/lib/jvm/java-6-sun/lib
JAVA_HOME=/usr/lib/jvm/java-6-sun
如果其中已经设置了CLASSPATH和JAVA_HOME,则将其修改为上面的形式,按ZZ保存退出。
java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07) Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
懒方法
1.从官网下载jdk7,安装到usr/lib/jvm,没有jvm文件夹可以创建一个 sudo mkdir jvm
2.配置jdk
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
因为只有这一个jdk,所以不用配置
java -version javac -version
参照文档如下:
Install the JDK
Uncompress it
tar -xvf jdk-7u2-linux-i586.tar.gz
(32bit)
tar -xvf jdk-7u2-linux-x64.tar.gz
(64bit)
JDK 7 package is extracted into ./jdk1.7.0_02 directory.- Now move the JDK 7 directory to/usr/lib
sudo mv ./jdk1.7.0_02 /usr/lib/jvm/jdk1.7.0
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo update-alternatives --config java
You will see output similar one below - choose the number of jdk1.7.0 - for example3
in this list:
$sudo update-alternatives –config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
3 /usr/lib/jvm/jdk1.7.0/jre/bin/java 3 manual mode
Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.
Check the version of you new JDK 7 installation:
java -version
java version “1.7.0”
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)
Repeat the above for:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
Enable mozilla firefox plugin:
32 bit:
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
64 bit:
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/