第一步:下载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
第三步:修改环境变量
vim ~/.bashrc
(如果没有安装vim先执行:sudo apt-get install vim)
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
第四步:配置默认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
第五步:查看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)
第六步:测试
package ubuntu.java.basic;
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));
}
}
david@ubuntu:~$ cd JavaTrain
david@ubuntu:~/JavaTrain$ ls
david@ubuntu:~/JavaTrain$ ls
ArrayTest.java
david@ubuntu:~/JavaTrain$ javac -d . ArrayTest.java
david@ubuntu:~/JavaTrain$ ls
ArrayTest.java ubuntu
david@ubuntu:~/JavaTrain$ java ubuntu.java.basic.ArrayTest
[0, 1, 4, 9, 16]
[hello, world, hi, you, good]
(责任编辑:IT) |