Ubuntu:OpenJDK 8 - 无法找到包 [英] Ubuntu: OpenJDK 8 - Unable to locate package

查看:68
本文介绍了Ubuntu:OpenJDK 8 - 无法找到包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚刚安装了 Ubuntu,这是我第一次在 Linux 环境中工作,所以请忍受我的小菜一碟.

So I just installed Ubuntu, and this is my first time working in a Linux environment, so bear with my noobishness here.

无论如何,我直接从 Oracle 下载了 Java 8 JDK,但我知道还有一个适用于 Java 8 的 OpenJDK.我有两个问题.

Anyway, I downloaded the Java 8 JDK directly from Oracle, but I understand there's also an OpenJDK for Java 8 as well. I have two questions.

  1. Oracle 版本和 OpenJDK 有什么区别.利弊?

  1. What is the difference between the Oracle version and OpenJDK. Pros/Cons?

当我尝试获取 OpenJDK 8 时,我不能.我正在粘贴终端命令和我在这里收到的错误消息,希望得到建议.再说一次,我对 Linux 非常陌生,此时我在我的第一个 Linux 发行版上使用了不到一个小时.

When I try and get OpenJDK 8, I can't. I'm pasting the terminal command and the error message I get here, hoping for advice. Again, very new to Linux, been on my first Linux distro ever for less than an hour here at this point.

user@computer:~/Java$ sudo apt-get install openjdk-8-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package openjdk-8-jdk

任何帮助将不胜感激.同时,我将只使用 Oracle 包.谢谢.

Any help would be appreciated. In the meantime, I'm just gonna use the Oracle package. Thanks.

所以,现在我遇到了一个新问题.我安装了 OpenJDK 7,它与 Maven 一起提供,并且在我意识到我得到了一个二合一的交易之前刚刚安装.现在我有 JDK 7、Eclipse 和 Maven,而且它们都在工作,但我坚持使用 JDK 7 而不是 8.

So, now I have a new problem. I installed OpenJDK 7, it came with Maven and just installed before I realized I was getting a two-for-one deal. Now I have JDK 7, and Eclipse, and Maven, and they're all working, but I'm stuck on JDK 7 rather than 8.

我看到下面有个链接,我打算早上去看看,现在是凌晨2点,我现在很累.对此新问题的任何其他建议将不胜感激,否则我肯定会在早上的第一件事中查看该链接.

I saw that there's a link below, I intend to check it out in the morning, it's 2am and I'm tired right now. Any other advice for this new issue would be appreciated, otherwise I will definitely be checking out that link first thing in the morning.

推荐答案

UPDATE:下面无需root权限安装

UPDATE: installation without root privileges below

如果已经有(半官方)存储库能够解决您的问题,我建议您不要在 ubuntu 系统上手动安装软件包.此外,使用 Oracle JDK 进行开发,只是为了避免(非常零星的)兼容性问题(我多年前尝试过,现在肯定更好).

I advise you to not install packages manually on ubuntu system if there is already a (semi-official) repository able to solve your problem. Further, use Oracle JDK for development, just to avoid (very sporadic) compatibility issues (i've tried many years ago, it's surely better now).

webupd8 存储库添加到您的系统:

Add the webupd8 repo to your system:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

安装您喜欢的 jdk 版本(从 java-6 到 java-9 的可用版本):

Install your preferred version of jdk (versions from java-6 to java-9 available):

sudo apt-get install oracle-java8-installer

<小时>

你也可以安装多个版本的jdk,混合openjdk和oracle版本.然后你可以使用命令 update-java-alternatives 在已安装的版本之间切换:


You can also install multiple version of jdk, mixing openjdk and oracle versions. Then you can use the command update-java-alternatives to switch between installed version:

# list available jdk
update-java-alternatives --list

# use jdk7
sudo update-java-alternatives --set java-7-oracle

# use jdk8
sudo update-java-alternatives --set java-8-oracle

要求

如果你得到 add-apt-repository: command not found 一定要安装 software-properties-common:

If you get add-apt-repository: command not found be sure to have software-properties-common installed:

sudo apt-get install software-properties-common

如果您使用的是旧版本的 Ubuntu:

If you're using an older version Ubuntu:

sudo apt-get install python-software-properties

<小时>

没有root权限的JDK安装

如果您在目标机器上没有管理员权限,最简单的方法是使用 sdkman 来安装 zulu 认证的 openjdk:

If you haven't administrator rights on your target machine your simplest bet is to use sdkman to install the zulu certified openjdk:

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java

注意:sdkman 也允许安装官方 Oracle JDK,尽管它不是默认选项.查看可用版本:

NOTE: sdkman allow to install also the official Oracle JDK, although it's not a the default option. View available versions with:

sdk ls java

安装所选版本:

sdk install java <version>

例如:

sdk install java 9.0.1-oracle

<小时>

命令词汇

  • sudo [command_arguments]:以超级用户权限执行命令.

  • sudo <command> [command_arguments]: execute a command with the superuser privilege.

add-apt-repository <PPA_id>:Ubuntu(就像每个 Debian 衍生产品,一般来说每个 Linux 发行版一样)有一个主要的软件包存储库处理诸如包依赖和更新之类的事情.在 Ubuntu 中,可以使用 PPA(个人包存档)扩展主存储库,它通常包含系统中不可用的包(就像 oracle jdk)或可用包的更新版本(例如:LTS 中的 LibreOffice 5 只能通过这个PPA).

add-apt-repository <PPA_id>: Ubuntu (just like every Debian derivatives and generally speaking every Linux distribution) has a main repository of packages that handle things like package dependencies and updating. In Ubuntu is possible to extend the main repository using a PPA (Personal Package Archive) that usually contains packages not available in the system (just like oracle jdk) or updated versions of available ones (example: LibreOffice 5 in LTS is available only through this PPA).

apt-get [install|update|upgrade|purge|...]:它是用于操作系统上每个存储库的状态(安装/更新/升级可以视为存储库当前状态的更改).

apt-get [install|update|upgrade|purge|...]: it's "the" command-line package handler used to manipulate the state of every repository on the system (installing / updating / upgrading can be viewed as an alteration of the repository current state).

在我们的例子中:使用命令 sudo add-apt-repository ppa:webupd8team/java 我们通知系统下一次存储库更新必须也从webupd8 存储库.

In our case: with the command sudo add-apt-repository ppa:webupd8team/java we inform the system that the next repository update must retrieve packages information also from webupd8 repo.

使用sudo apt-get update,我们实际上更新了系统存储库(所有这些操作都需要超级用户权限,因此我们在命令前添加了sudo).

With sudo apt-get update we actually update the system repository (all this operations requires superuser privileges, so we prepend sudo to the commands).

sudo apt-get install oracle-java8-installer

  • update-java-alternatives(update-alternatives 的特定 Java 版本):在 Ubuntu 中,多个软件包提供相同的功能(浏览互联网、编译邮件、编辑文本文件或提供 java/javac 可执行文件...).为了允许系统在给定特定任务的情况下选择用户收藏夹工具,使用 symlinks/etc/alternatives/ 被使用.尝试按照上面的指示更新 jdk(在 java 7 和 java 8 之间切换)并查看如何更改此命令的输出:

  • update-java-alternatives (a specific java version of update-alternatives): in Ubuntu several packages provides the same functionality (browse the internet, compile mails, edit a text file or provides java/javac executables...). To allows the system to choose the user favourites tool given a specific task a mechanism using symlinks under /etc/alternatives/ is used. Try to update the jdk as indicated above (switch between java 7 and java 8) and view how change the output of this command:

ls -l/etc/alternatives/java*

在我们的例子中:sudo update-java-alternatives --set java-8-oracle 更新/etc/alternatives 下的符号链接以指向 java-8-oracle可执行文件.

In our case: sudo update-java-alternatives --set java-8-oracle update symlinks under /etc/alternatives to point to java-8-oracle executables.

附加:

  • ma​​n :开始使用 man 来阅读关于(几乎)每个 shell 命令及其选项(每个我在这个小答案中提到的命令有一个手册页,请尝试 man update-java-alternatives).

  • man <command>: start using man to read a really well written and detailed help on (almost) every shell command and its options (every command i mention in this little answer has a man page, try man update-java-alternatives).

apt-cache search :查询 APT 缓存以搜索与提供的 search_key 相关的包(可以是包名或包装说明中的一些词).

apt-cache search <search_key>: query the APT cache to search for a package related with the search_key provided (can be the package name or some word in package description).

apt-cache show <package>:提供特定包的 APT 信息(包版本、安装与否、描述).

apt-cache show <package>: provides APT information for a specific package (package version, installed or not, description).

这篇关于Ubuntu:OpenJDK 8 - 无法找到包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆