linux Ubuntu安装jdk1.8

1.查看系统信息

命令: cat /proc/version

Linux version 3.2.0-29-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #46-Ubuntu SMP ...... UTC 2012

2.查看系统是32还是64位

命令:getconf LONG_BIT

64

3.查看系统是否已经安装有jdk

命令:java -version

java version "1.6.0_45"

Java(TM) SE Runtime Environment (build 1.6.0_45-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

4.完整卸载系统上的jdk/jre

命令1:卸载openjdk(注意不是oracle jdk)

若要卸载默认的openjdk:sudo apt-get purge openjdk-*

只看最后一行

xxx upgraded, xxx newly installed, xxx to remove and 123 not upgraded.

命令2:卸载oracle jdk6

http://askubuntu.com/questions/117543/how-to-remove-oracle-jdk

whereis java

java: /usr/bin/java /usr/local/java /usr/share/java /opt/jdk1.6.0_45/bin/java

sudo rm -r /opt/jdk1.6.0_45/

sudo rm -rf /usr/local/java

sudo rm -rf /usr/share/java

5.创建一个文件夹用来存放jdk和jre

sudo mkdir -p /usr/local/java

6.官网下载jdk 根据系统版本

因为我是64位,并且需要指定安装目录,所以选择了压缩版tar.gz


linux Ubuntu安装jdk1.8_第1张图片
官网下载符合自己的jdk版本

7.使用类似FileZilla的工具上传jdk

上传进度

8.安装

命令:sudo tar xvzf jdk-8u121-linux-x64.tar.gz

内容太多不方便展示...

9.安装好以后进行JAVA_HOME配置

sudo gedit /etc/profile

或者

sudo nano /etc/profile

JAVA_HOME=/usr/local/java/jdk1.8.0_121

JRE_HOME=/usr/local/java/jre1.8.0_121 (如果只下载了jdk:/usr/local/java/jdk1.8.0_121/jre)

PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin

export JAVA_HOME

export JRE_HOME

export PATH

按照最下面的命令提示:写完保存:ctrl+o  ctrl+x

10.安装的3条命令:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_121/bin/java" 1

update-alternatives: renaming java link from /usr/bin/java to /usr/local/java.

update-alternatives: warning: forcing reinstallation of alternative /usr/local/java/jdk1.8.0_121/bin/java because link group java is broken.

update-alternatives: warning: not replacing /usr/local/java with a link.

警告⚠️可以忽略,保险起见可以再执行一次,就不会报错了

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_121/bin/javac" 1

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_121/bin/javaws" 1

java -version

java version "1.8.0_121"

Java(TM) SE Runtime Environment (build 1.8.0_121-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)


参考资料:

http://www.jianshu.com/u/064e496ecbec

http://www.wikihow.com/Install-Oracle-Java-on-Ubuntu-Linux

你可能感兴趣的:(linux Ubuntu安装jdk1.8)