1、到oracle 的官网下载
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
选择 accept license ,然后选择适合自己机型的JDK下载。
2、解压文件,修改文件名
$ sudo mkdir /usr/lib/jvm $ sudo tar zxvf jdk-8u51-linux-x64.tar.gz -C /usr/lib/jvm $ cd /usr/lib/jvm $ sudo mv jdk1.8.0_51 java
3、添加环境变量
$ sudo gedit ~/.bashrc
加入如下内容
export JAVA_HOME=/usr/lib/jvm/java export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
4、配置默认JDK版本
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/bin/java 300 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/bin/javac 300 sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java/bin/jar 300 sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java/bin/javah 300 sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java/bin/javap 300
然后执行
sudo update-alternatives --config java
若是初次安装 JDK, 将提示
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java/bin/java 无需配置。
若是非初次安装,将有不同版本的 JDK 选项。
5、测试
$ java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
时间: 2024-11-10 08:28:27