注意:这是一个老问题,答案反映了当时的世界。现代的Ubuntu发行版有OpenJDK可供安装
sudo apt install default-jdk
我正在尝试在Ubuntu Linux发行版上安装Java开发工具包(JDK),但我无法安装它。
在Ubuntu上安装它的步骤是什么?
注意:这是一个老问题,答案反映了当时的世界。现代的Ubuntu发行版有OpenJDK可供安装
sudo apt install default-jdk
我正在尝试在Ubuntu Linux发行版上安装Java开发工具包(JDK),但我无法安装它。
在Ubuntu上安装它的步骤是什么?
当前回答
参考问Ubuntu问题如何设置OpenJDK的JAVA_HOME ?,
如何在Ubuntu (Linux)下安装Open JDK (Java开发工具包)?
Open Terminal from Application Dash or press Ctrl+Alt+T Update repository: sudo add-apt-repository ppa:openjdk-r/ppa # only Ubuntu 17.4 and earlier sudo apt update Optional: To search available distributions of openjdk, use the following command: apt search openjdk Install the appropriate version with the following command: sudo apt install openjdk-8-jdk sudo apt install openjdk-8-source #this is optional, the jdk source code For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path... export JAVA_HOME=/usr/lib/jvm/java-8-openjdk (Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.) For PATH (Environment Variable) type command as shown below, in Terminal: export PATH=$PATH:$JAVA_HOME/bin To check your installation: java -version
其他回答
注:WebUpd8团队的PPA已于2019年4月16日终止。因此,这个PPA没有任何Java文件。更多信息可以在PPA的Launchpad页面上找到。因此,由于历史原因,下面的方法不再适用和存在。
在Ubuntu上安装Java 8
首先,您需要在您的系统中添加webupd8team Java PPA存储库,并使用以下命令集安装Oracle Java 8。
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
验证已安装的Java版本
使用上述步骤成功安装Oracle Java后,使用以下命令验证已安装的版本。
$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
###配置Java环境
在webpd8的ppa存储库中还提供了一个用于设置环境变量的包,使用以下命令安装此包。
$ sudo apt-get install oracle-java8-set-default
参考
Install the appropriate version of OpenJDK JAVA_VERSION=8 sudo add-apt-repository -y ppa:openjdk-r/ppa sudo apt-get update sudo apt-get -qq install -y openjdk-$JAVA_VERSION-jdk Set Environment Variables in /etc/profile.d/jdk.sh JAVA_HOME=/usr/lib/jvm/java-$JAVA_VERSION-openjdk-amd64 echo "export JAVA_HOME=$JAVA_HOME" | sudo tee -a /etc/profile.d/jdk.sh echo "export J2SDKDIR=$JAVA_HOME" | sudo tee -a /etc/profile.d/jdk.sh echo "export J2REDIR=$JAVA_HOME/jre" | sudo tee -a /etc/profile.d/jdk.sh echo "export PATH=$PATH:$JAVA_HOME/bin:$J2REDIR/bin" | sudo tee -a /etc/profile.d/jdk.sh Check your installation /bin/bash /etc/profile.d/jdk.sh java -version echo $JAVA_HOME echo $J2REDIR echo $PATH
如果你想安装Oracle JDK,你可以使用这个自动的脚本来完成所有的工作。
在作者的博客上有详细的使用说明。
你可以通过apt-get安装:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java11-installer
之后,不要忘记检查版本:
java -version
参考问Ubuntu问题如何设置OpenJDK的JAVA_HOME ?,
如何在Ubuntu (Linux)下安装Open JDK (Java开发工具包)?
Open Terminal from Application Dash or press Ctrl+Alt+T Update repository: sudo add-apt-repository ppa:openjdk-r/ppa # only Ubuntu 17.4 and earlier sudo apt update Optional: To search available distributions of openjdk, use the following command: apt search openjdk Install the appropriate version with the following command: sudo apt install openjdk-8-jdk sudo apt install openjdk-8-source #this is optional, the jdk source code For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path... export JAVA_HOME=/usr/lib/jvm/java-8-openjdk (Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.) For PATH (Environment Variable) type command as shown below, in Terminal: export PATH=$PATH:$JAVA_HOME/bin To check your installation: java -version