在 Ubuntu 上安装 Java 7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16263556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:03:43  来源:igfitidea点击:

Installing Java 7 on Ubuntu

javaubuntuinstallation

提问by foralobo

to install java I have always used the classic way from the terminal. I would like to install java manually. I placed the folder of the JDK on the desk and I set environment variables (PATH, CLASSPATH and JAVA_HOME). From the terminal, if I type java -versionI get printed

安装java我一直使用终端的经典方式。我想手动安装java。我将 JDK 的文件夹放在桌子上,并设置了环境变量(PATH、CLASSPATH 和 JAVA_HOME)。从终端,如果我输入java -version我会打印

foralobo@ubuntu-vincy:~$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

But when I try to install eclipse or netbeans, the system warns by saying that there is no java installed on the machine.

但是当我尝试安装eclipse或netbeans时,系统警告说机器上没有安装java。

What is missing to compleatare manual installation? (Ubuntu 13.04)

完成手动安装缺少什么?(Ubuntu 13.04)

采纳答案by flup

This answer used to describe how to install Oracle Java 7. This no longer works since Oracle end-of-lifed Java 7 and put the binary downloads for versions with security patches behind a paywall. Also, OpenJDK has grown up and is a more viable alternative nowadays.

这个答案曾经描述过如何安装 Oracle Java 7。自从 Oracle 终止 Java 7 并将带有安全补丁的版本的二进制下载放在付费墙之后,这不再有效。此外,OpenJDK 已经成长起来,现在是一个更可行的替代方案。

In Ubuntu 16.04 and higher, Java 7 is no longer available. Usually you're best off installing Java 8 (or 9) instead.

在 Ubuntu 16.04 及更高版本中,Java 7 不再可用。通常您最好安装 Java 8(或 9)。

sudo apt-get install openjdk-8-jre

or, f you also want the compiler, get the jdk:

或者,如果您还需要编译器,请获取 jdk:

sudo apt-get install openjdk-8-jdk

In Trusty, the easiest way to install Java 7 currently is to install OpenJDK package:

在 Trusty 中,目前安装 Java 7 最简单的方法是安装 OpenJDK 包:

sudo apt-get install openjdk-7-jre

or, for the jdk:

或者,对于 jdk:

sudo apt-get install openjdk-7-jdk

If you are specifically looking for Java 7 on a version of Ubuntu that no longer supports it, see https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher.

如果您在不再支持它的 Ubuntu 版本上专门寻找 Java 7,请参阅https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16- 04 或更高

回答by Brent Robinson

In addition to flup's answer you might also want to run the following to set JAVA_HOME and PATH:

除了 flup 的回答,您可能还想运行以下命令来设置 JAVA_HOME 和 PATH:

sudo apt-get install oracle-java7-set-default

More information at: http://www.ubuntuupdates.org/package/webupd8_java/precise/main/base/oracle-java7-set-default

更多信息请访问:http: //www.ubuntuupdates.org/package/webupd8_java/precise/main/base/oracle-java7-set-default

回答by Sopan kokre

sudo apt-get update
sudo apt-get install openjdk-7-jdk

and if you already have other JDK versions installed

如果您已经安装了其他 JDK 版本

sudo update-alternatives --config java

then select the Java 7 version.

然后选择 Java 7 版本。

回答by Pawe? Pra?ak

Oracle Java 1.7.0 from .deb packages

来自 .deb 包的 Oracle Java 1.7.0

wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7
sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source 
sudo apt-get dist-upgrade

Workaround for 1.7.0_51

1.7.0_51 的解决方法

There is an Issue 123currently in OAB and a pull request

目前在 OAB 中有一个问题 123和一个拉取请求

Here is the patched vesion:

这是补丁版本:

wget https://raw.github.com/ladios/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7
sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source 
sudo apt-get dist-upgrade

回答by Siddharth

flup's answeris the best but it did not work for me completely. I had to do the following as well to get it working:

flup 的答案是最好的,但它并不完全适合我。我还必须执行以下操作才能使其正常工作:

  1. export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/
  2. chmod 777on the folder
  3. ./gradlew build- Building Hibernate
  1. export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/
  2. chmod 777在文件夹上
  3. ./gradlew build- 构建休眠

回答by Mehran

I think you should consider Java installation procedure carefully. Following is the detailed process which covers almost all possible failures.

我认为您应该仔细考虑 Java 安装程序。以下是涵盖几乎所有可能故障的详细过程。

Installing Java with apt-getis easy. First, update the package index:

使用apt-get安装 Java很容易。首先,更新包索引:

sudo apt-get update

Then, check if Java is not already installed:

然后,检查是否尚未安装 Java:

java -version

If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:

如果返回“该程序java可以在以下包中找到”,则Java尚未安装,因此执行以下命令:

sudo apt-get install default-jre

You are fine till now as I assume.

正如我假设的那样,你到现在都很好。

This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:

这将安装 Java 运行时环境 (JRE)。如果您需要 Java 开发工具包 (JDK),它通常用于编译 Java 应用程序(例如 Apache Ant、Apache Maven、Eclipse 和 IntelliJ IDEA),请执行以下命令:

sudo apt-get install default-jdk

That is everything that is needed to install Java.

这就是安装 Java 所需的一切。

Installing OpenJDK 7:

安装 OpenJDK 7:

To install OpenJDK 7, execute the following command:

要安装 OpenJDK 7,请执行以下命令:

sudo apt-get install openjdk-7-jre 

This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:

这将安装 Java 运行时环境 (JRE)。如果您需要 Java 开发工具包 (JDK),请执行以下命令:

sudo apt-get install openjdk-7-jdk

Installing Oracle JDK:

安装 Oracle JDK:

The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.

Oracle JDK 是官方的 JDK;但是,Oracle 不再提供它作为 Ubuntu 的默认安装。

You can still install it using apt-get. To install any version, first execute the following commands:

您仍然可以使用 apt-get 安装它。要安装任何版本,首先执行以下命令:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Then, depending on the version you want to install, execute one of the following commands:

然后,根据您要安装的版本,执行以下命令之一:

Oracle JDK 7:

甲骨文 JDK 7:

sudo apt-get install oracle-java7-installer

Oracle JDK 8:

甲骨文 JDK 8:

sudo apt-get install oracle-java8-installer

回答by Abhijit Bashetti

Download java jdk<version>-linux-x64.tar.gzfile from https://www.oracle.com/technetwork/java/javase/downloads/index.html.

jdk<version>-linux-x64.tar.gzhttps://www.oracle.com/technetwork/java/javase/downloads/index.html下载 java文件。

Extract this file where you want. like: /home/java(Folder name created by user in home directory).

将此文件解压缩到您想要的位置。如:(/home/java用户在主目录中创建的文件夹名称)。

Now open terminal. Set path JAVA_HOME=pathof your jdk folder(open jdk folder then right click on any folder, go to properties then copy the path using select all) and paste here.

现在打开终端。设置JAVA_HOME=pathjdk 文件夹的路径(打开 jdk 文件夹,然后右键单击任何文件夹,转到属性,然后使用全选复制路径)并粘贴到此处。

Like: JAVA_HOME=/home/xxxx/java/JDK1.8.0_201

喜欢: JAVA_HOME=/home/xxxx/java/JDK1.8.0_201

Let Ubuntu know where our JDK/JRE is located.

让 Ubuntu 知道我们的 JDK/JRE 所在的位置。

sudo update-alternatives --install /usr/bin/java java /home/xxxx/java/jdk1.8.0_201/bin/java 20000
sudo update-alternatives --install /usr/bin/javac javac /home/xxxx/java/jdk1.8.0_201/bin/javac 20000
sudo update-alternatives --install /usr/bin/javaws javaws /home/xxxx/java/jdk1.8.0_201/bin/javaws 20000

Tell Ubuntu that our installation i.e., jdk1.8.0_05 must be the default Java.

告诉 Ubuntu 我们的安装即 jdk1.8.0_05 必须是默认的 Java。

sudo update-alternatives --set java /home/xxxx/sipTest/jdk1.8.0_201/bin/java
sudo update-alternatives --set javac /home/xxxx/java/sipTest/jdk1.8.0_201/bin/javac
sudo update-alternatives --set javaws /home/xxxxx/sipTest/jdk1.8.0_201/bin/javaws

Now try:

现在尝试:

$ sudo update-alternatives --config java

There are 3 choices for the alternative java (providing /usr/bin/java).

替代 java(提供/usr/bin/java)有 3 种选择。

  Selection    Path                                  Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-oracle1/bin/java   1047      auto mode
  1            /usr/bin/gij-4.6                       1046      manual mode
  2            /usr/lib/jvm/java-6-oracle1/bin/java   1047      manual mode
  3            /usr/lib/jvm/jdk1.7.0_75/bin/java      1         manual mode

Press enter to keep the current choice [*], or type selection number: 3

按 Enter 保留当前选择 [ *],或键入选择编号:3

update-alternatives: using /usr/lib/jvm/jdk1.7.0_75/bin/java to provide /usr/bin/java (java) in manual mode

Repeat the above for:

重复以上操作:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

回答by Akitha_MJ

Open Applicaction -> Accessories -> Terminal

Type commandline as below...

sudo apt-get install openjdk-7-jdk

Type commandline as below...

apt-cache search jdk

(Note: openjdk-7-jdk is symbolically used here. You can choose the JDK version as per your requirement.)

For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path...

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk

(Note: "/usr/lib/jvm/java-7-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" using your installation path...

export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin

(Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)

Check for "open jdk" installation, just type command in "Terminal" as shown below

javac -version

回答by Aniket Thakur

PPA method no longer works.

PPA 方法不再有效。

While Oracle Java 6 and 7 are not supported for quite a while, they were still available for download on Oracle's website until recently.

However, the binaries were removed about 10 days ago (?), so the Oracle Java (JDK) 6 and 7 installers available in the WebUpd8 Oracle Java PPA no longer work.

Oracle Java 6 and 7 are now only available for those with an Oracle Support account (which is not free), so I can't support this for the PPA packages.

虽然 Oracle Java 6 和 7 有很长一段时间不受支持,但直到最近,它们仍然可以在 Oracle 的网站上下载。

但是,二进制文件在大约 10 天前被删除 (?),因此 WebUpd8 Oracle Java PPA 中可用的 Oracle Java (JDK) 6 和 7 安装程序不再工作。

Oracle Java 6 和 7 现在仅适用于拥有 Oracle Support 帐户(不是免费的)的用户,因此我无法为 PPA 包提供支持。

Source : http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.htmlDated : June 2017

来源:http: //www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html日期:2017 年 6 月

Oracle's download pagesays

Oracle 的下载页面

Updates for Java SE 7 released after April 2015, and updates for Java SE 6 released after April 2013 are only available to Oracle Customers through My Oracle Support (requires support login).

Java SE Advanced offers users commercial features, access to critical bug fixes, security fixes, and general maintenance".

2015 年 4 月之后发布的 Java SE 7 更新和 2013 年 4 月之后发布的 Java SE 6 更新仅通过 My Oracle Support 提供给 Oracle 客户(需要支持登录)。

Java SE Advanced 为用户提供商业功能、访问关键错误修复、安全修复和一般维护”。

I had to download it from Oracle archives - http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

我不得不从 Oracle 档案下载它 - http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

You need an account for this though.

不过,您需要一个帐户。