1.到ORACLE网站
- http://www.oracle.com/technetwork/java/javase/downloads
解压:tar xzvf jdk-7u2-linux-i586.tar.gz
解压缩之后的文件夹移动到/usr/local中:mv jdk1.7.0-17 /usr/local
编辑系统变量sudo gedit /etc/profile添加内容
- JAVA_HOME=/usr/local/jdk1.7.0-17
- PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
- CLASS_PATH=$JAVA_HOME/lib
- export JAVA_HOME
- export CLASS_PATH
- export PATH
设置Sun JDK为默认JDK版本,因为Ubuntu自带了OpenJDK,所以我们得设置这一步
- sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/jdk1.7.0_17/bin/java" 1
- sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/jdk1.7.0_17/bin/javac" 1
将我们的安装的java设置为系统默认的java
- sudo update-alternatives --set java /usr/local/jdk1.7.0_17/bin/java
- sudo update-alternatives --set javac /usr/local/jdk1.7.0_17/bin/javac
系统重启之后profile文件生效
使用如下命令进行检测
- java -version
- 输入如下信息:
- java version "1.7.0_17"
- Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
- Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode)
- javac -version
- 输出如下信息:
- javac 1.7.0_17