1. 修改linux软件源
此处以阿里云软件源为例,其他软件源如清华、中科院软件源可以自行百度。 去阿里云软件源网站 https://opsx.alibaba.com/mirror 找到linux所对应的版本,点击右边的帮助,复制类似一下内容:
deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
进入/etc/apt文件夹,修改sources.list文件,将以上复制内容替换原来的所有内容。
2. 运行安装命令
安装java8运行
apt-get install oracle-java8-installer
安装java9运行
apt-get install oracle-java9-installer
网上还流传着其他的apt-get语句,语句的不同主要是因为软件源的不同,对于阿里云软件源,jdk的软件包名字叫 oracle -java8/9-installer,但是对于其他的软件源,jdk软件包有不同的名字,可以试着运行java,终端会提示软件包的名字,按照提示操作就好。