手动安装
1)安装
下载jdk-7-linux-i586.tar.gz
$ cd /usr/lib$ sudo mkdir jvm
$ cd <jdk压缩文件目录>
$ sudo tar -zxvf jdk-7-linux-i586.tar.gz -C /usr/lib/jvm
$ cd /usr/lib/jvm
$ sudo mv jdk1.7.0/ java-7-sun
2)修改环境变量
$ gedit ~/.bashrc
添加以下内容:
export JAVA_HOME=/usr/lib/jvm/java-7-sun export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
然后执行:
$ source ~/.bashrc
3)配置默认JDK版本
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-sun/bin/javac 300
$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-7-sun/bin/jar 300
$ sudo update-alternatives --config java
4)查看java版本号
$ java -version
输出:
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode)
5)测试:
import java.util.*;
public class ArrayTest {
public static void main(String[] args) {
int[] a = new int[5];
for (int i=0;i<a.length;i++)
a[i] = i*i;
System.out.println(Arrays.toString(a));
String[] b = {"hello","world","hi","you","good"};
System.out.println(Arrays.toString(b));
}
}
javac -d . ArrayTest.java
java ArrayTest