Ubuntu / Google Compute Engine / Google Cloud:安装JAVA JDK8 或者 JAVA JDK 9, Install Oracle Java 8 / 9 in Ubuntu 16.04, Linux Mint 18

1. Add the PPA.

Open terminal (Ctrl+Alt+T) and run the command:

sudo add-apt-repository ppa:webupd8team/java

Type in your password when it asks and hit Enter.

2. Update and install the installer script:

Run commands to update system package index and install Java installer script:

sudo apt update && sudo apt install oracle-java8-installer

安装Java 9的看这里: You may replace oracle-java8-installer with oracle-java9-installer to install Java 9. 

While the install process, you have to accept Java license to continue downloading & installing Java binaries.

3. Check the Java version

To check the Java version after installing the package, run command:

javac -version


4. Set Java environment variables

The PPA also contains a package to automatically set Java environment variables, just run command:

sudo apt install oracle-java8-set-default

安装Java 9的看这里:For Java 9, install the package oracle-java9-set-default instead.

 

Google Compute Engine 实例安装 Java JDK, 如果以上方法不行的话,就用下载包安装吧!

  1. 官网下载 JAVA JDK 9 : 选中 Accept License Agreement,点击下载 jdk-9.0.4_linux-x64_bin.tar.gz
  2. 运行一下代码:
    tar -xvf ~/Downloads/jdk-9.0.4_linux-x64_bin.tar.gz
    sudo mkdir -p /usr/lib/jvm/jdk-9.0.4
    sudo mv jdk-9.0.4/* /usr/lib/jvm/jdk-9.0.4/
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-9.0.4/bin/java" 1
    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-9.0.4/bin/javac" 1
    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk-9.0.4/bin/javaws" 1
  3. 注意,后面的 1 是参数,不要删除
  4. 编辑 Edit the system path in file /etc/profile 设着PATH全局变量
    sudo vi /etc/profile

    在末尾添加:

    JAVA_HOME=/usr/lib/jvm/jdk-9.0.4
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    export JAVA_HOME
    export PATH

    然后source一下:

    source /etc/profile
  5. 执行下面代码,看是安装否成功:
    java -version

 

本文:Ubuntu:安装JAVA 8 或者 JAVA 9, Install Oracle Java 8 / 9 in Ubuntu 16.04, Linux Mint 18

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.