1.下载jdk-7-linux-x64.rpm(http://www.Oracle.com/technetwork/Java/javase/downloads/java-se-jdk-7-download-432154.html)
2. su切换到root权限
3. /usr/java/jdk1.7.0 rpm -ivh jdk-7-linux-x64.rpm,默认安装路径为 /usr/java/jdk1.7.0
4. vi /etc/profile
5. 在profile最后追加:
- export JAVA_HOME=/usr/java/jdk1.7.0
- export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- export PATH=$PATH:$JAVA_HOME/bin
6. source /etc/profile
7. 安装update-alternatives
update-alternatives –install /usr/bin/java java /usr/java/jdk1.7.0/bin/java 60
配置jdk
update-alternatives –config java
然后出现
- 共有 2 个程序提供“java”。
- 选择 命令
- ———————————————–
- *+ 1 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
- 2 /usr/java/jdk1.7.0/bin/java
- 按 Enter 来保存当前选择[+],或键入选择号码:2
回车即可。
java -version 输出
- java version “1.7.0”
- Java(TM) SE Runtime Environment (build 1.7.0-b147)
- Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)