Ubuntu安装sun jdk 步骤

下载JDK

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

我下载的是jdk1.7.0_40

解压

我解压路径是/home/lincoln/developer/jdk1.7.0_40


在最高权限下拷贝到/usr/lib/jvm/


sudo cp -r /home/lincoln/developer/jdk1.7.0_40/ /usr/lib/jvm/



修改环境变量

sudovi /etc/environment

PATH后接上:

PATH"......:/usr/lib/jvm/jdk1.7.0_40/bin"

添加:
CLASSPATH=.:/usr/lib/jvm/jjdk1.7.0_40/lib
JAVA_HOME=/usr/lib/jvm/ jdk1.7.0_40

使环境变量生效:

source~/.bashrc



一般情况下ubuntu可能设置了默认的jdk比如openjdk

现在要替换默认的jdk

1

sudoupdate-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_40/bin/java 300

2

sudoupdate-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_40/bin/javac 300

3

sudoupdate-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_40/bin/jar 300

4

sudoupdate-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.7.0_40/bin/javah 300

5

sudoupdate-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0_40/bin/javap 300

完成后

sudoupdate-alternatives --config java

出现以下结果

2个候选项可用于替换 java(提供 /usr/bin/java)

选择 路径 优先级 状态

------------------------------------------------------------

*0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 自动模式

1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 手动模式

2 /usr/lib/jvm/jdk1.7.0_40/bin/java 300 手动模式

要维持当前值[*]请按回车键,或者键入选择的编号:

输入 2回车后

update-alternatives:using /usr/lib/jvm/jdk1.7.0_40/bin/java to provide /usr/bin/java(java) in 手动模式


最后检查

java-version测试一下

javaversion "1.7.0_40"

Java(TM)SE Runtime Environment (build 1.7.0_40-b43)

JavaHotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)


javacjavah javap java一样:

update-alternatives--config javac

update-alternatives--config javah

update-alternatives--config javap



你可能感兴趣的:(java,jdk,ubuntu,sun)