注意:这是一个老问题,答案反映了当时的世界。现代的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目录。

其他回答

如果你想使用Java 10之外的AdoptOpenJDK发行版,你可以使用AdoptOpenJDK网站上描述的官方存储库(也适用于Debian):

Import the official AdoptOpenJDK GPG key by running the following command: wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add - Import the AdoptOpenJDK DEB repository by running the following command: sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ If you get a command not found error, try running: apt-get install -y software-properties-common Then repeat the first command. Refresh your package list with apt-get update and then install your chosen AdoptOpenJDK package. For example, to install OpenJDK 8 with the HotSpot VM, run: apt-get install <adoptopenjdk-8-hotspot>

您可以在https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/pool/main/a/下找到可用的软件包名称/ Java版本

来自Ubuntu网站的Wiki:

对于Ubuntu 10.04 LTS, sun-java6包已经从Ubuntu归档文件的Multiverse部分中删除了。建议使用openjdk-6。

如果您不能从专有的Sun JDK/JRE切换到OpenJDK,您可以从规范合作伙伴存储库安装Sun -java6包。你可以通过命令行配置你的系统来使用这个存储库:

 sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
 sudo apt-get update   
 sudo apt-get install sun-java6-jre sun-java6-plugin
 sudo update-alternatives --config java

对于Ubuntu 10.10, sun-java6包已经从Ubuntu归档文件的Multiverse部分中删除了。建议使用openjdk-6。

如果您不能从专有的Sun JDK/JRE切换到OpenJDK,您可以从规范合作伙伴存储库安装Sun -java6包。你可以通过命令行配置你的系统来使用这个存储库:

 sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
 sudo apt-get update   
 sudo apt-get install sun-java6-jre sun-java6-plugin
 sudo update-alternatives --config java

在Debian上你可以试试

apt-get install default-jdk

我推荐JavaPackage。

这很简单。您只需要按照说明从Oracle tar.gz文件创建.deb包。

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