折腾了一个多小时了,终于算是装上了
参照教程
http://www.cnblogs.com/plinx/archive/2013/06/01/3113106.html
我是从官网下的安装包,然后解压的
主要是配置环境后source /etc/profile
时一直报错: export: command not found
后来发现必须再进行如下配置:
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
具体步骤如下:
1、到 Oracle 的官网下载
选择 accept license ,然后选择适合自己机型的JDK下载。
2、解压文件,修改文件名
$ sudo mkdir /usr/lib/jvm
$ sudo tar zxvf jdk-7u21-linux-i586.tar.gz -C /usr/lib/jvm
$ cd /usr/lib/jvm
$ sudo mv jdk1.7.0_21 java
3、添加环境变量
$ sudo vim ~/.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
Nothing to configure.
若是非初次安装,将有不同版本的 JDK 选项。
5、测试
$ java -version
java version “1.8.0_181”
Java™ SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot™ 64-Bit Server VM (build 25.181-b13, mixed mode)