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

sudo apt install default-jdk

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

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


当前回答

执行这一系列命令(插入、更新和安装),您就可以开始了。

首先添加存储库: Sudo add-apt-repository ppa:webupd8team/java 更新: Sudo apt-get update 安装: Sudo apt-get install oracle-java7-installer

其他回答

可以使用sudo apt-get install default- JDK terminal命令安装默认版本的JDK。

在安装Java之前,首先输入sudo apt-get update terminal命令,然后输入install terminal命令。你可以从这里得到更多信息。

简单地运行:

sudo apt-get install default-jdk

你也可以很容易地安装Oracle的JDK 1.7;作为一个例子,这是如何安装JDK 1.7.0_13;

从Oracle的网站下载JDK。下载到最新版本的链接总是从http://java.oracle.com。

作为根,做;

cd /usr/local
tar xzf <the file you just downloaded>

作为普通用户,在~/中添加或更改这两行。型材要指向安装;

export JAVA_HOME=/usr/local/jdk1.7.0_13
export PATH=$PATH:$JAVA_HOME/bin

如果是更新,您可能还想删除/usr/local中的旧java安装目录。

登出并重新登录(或做。~/.profile),一切都应该正常工作。

Oracle JDK的缺点是它不会像OpenJDK那样随系统的其他部分一起更新,所以如果您正在运行需要它的程序,我主要会考虑使用它。

安装在ubuntu 18.04中

我的解决办法是,

$ sudo apt update

安装OpenJDK 8:

$ sudo apt install openjdk-8-jdk

通过运行以下命令来验证Java安装,该命令将打印Java版本:

$ java -version

输出应该是这样的:

输出:

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

我只是在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目录。