注意:这是一个老问题,答案反映了当时的世界。现代的Ubuntu发行版有OpenJDK可供安装

sudo apt install default-jdk

我正在尝试在Ubuntu Linux发行版上安装Java开发工具包(JDK),但我无法安装它。

在Ubuntu上安装它的步骤是什么?


当前回答

我只是在Ubuntu虚拟机上做了这个。我是这样做的。

Ubuntu comes with the Java JRE installed, but not the JDK. Java -version gives the JRE, not the JDK. Run javac -version. If the JDK isn't installed, you will get an error. Run the following command in the terminal to get the JDK: sudo apt install default-jdk. Now, run which javac. The output should be /usr/bin/javac. It has now been installed. IntelliJ won't let us use this path because it is the binary of javac. Go to Project Structure > Project Settings > Project. Where it says 'Project SDK', add a JDK. Then go to /usr/lib/jvm. Now you should be able to compile java projects in IntellIJ.

您可能必须编辑配置,以便IntelliJ知道在哪里查找您的主类。执行命令>编辑配置。为main类添加主类,并将项目的根目录添加为Working目录。

其他回答

如果你不想为Ubuntu安装OpenJDK: JDK源安装程序,可以试试这个方法

参考问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

在2019年初Oracle Java许可证变更之前,以下操作可以正常工作。

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

PPA将终止,直到作者找到解决许可证问题的解决方案。

看一看OpenJDK。它是Linux上的标准JVM实现。

我也有同样的问题,但没有一条评论对我有用。最后,我注意到我禁用了我的更新。当我重新激活它,所以sudo apt-get更新工作正确,问题得到解决。 (更新系统设置>软件和更新>更新选项卡 这里我勾选了两个重要更新和推荐更新的第一个选项)。