简体   繁体   English

使用 apt-get 在 Google Compute Engine 实例上安装 Java 8

[英]Installing Java 8 on a Google Compute Engine instance with apt-get

I ran this command with apt-get but have received this error.我用 apt-get 运行了这个命令,但收到了这个错误。 I am not too sure how to resolve this.我不太清楚如何解决这个问题。 Is this come core mistake I have made using apt-get, asking for something impossible?这是我使用 apt-get 所犯的核心错误,要求不可能的事情吗? Does anyone understand the root cause that prevents it from installing?有谁知道阻止它安装的根本原因?

sudo apt-get install openjdk-8-jdk                                                                                       
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 openjdk-8-jdk : Depends: openjdk-8-jre (= 8u171-b11-1~bpo8+1) but it is not going to be installed
                 Depends: openjdk-8-jdk-headless (= 8u171-b11-1~bpo8+1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

It's a one liner 这是一个班轮

sudo apt-get -y install default-jdk
java -version

I had a similar problem attempting to install the Java 8 JDK on one of my Google Compute Engine instances and found a solution here (but read about modifications below first): 我在尝试在一个Google Compute Engine实例上安装Java 8 JDK时遇到类似的问题,并在此处找到了解决方案(但请先阅读以下修改内容):

http://cgrant.io/tutorials/gcp/compute/gce/how-to-deploy-a-java-application-to-google-compute-engine/ http://cgrant.io/tutorials/gcp/compute/gce/how-to-deploy-a-java-application-to-google-compute-engine/

In the "Deploy scripts" section, inside the code block shown for install.sh, I pulled out the applicable lines and ran them with a few modifications as follows: 在“部署脚本”部分的install.sh所示代码块中,我拉出了适用的代码行,并对其进行了一些修改,如下所示:

  • I ran all commands with sudo, but it would probably be more appropriate to do as he does and "su -" (change to root) before you run any of the commands. 我使用sudo运行了所有命令,但是在运行任何命令之前,按照他的做法执行“ su-”(更改为root)可能更合适。
  • Changed owner and group to my own as I got permissions errors despite running all commands with sudo (you won't need to do this if you run commands as root instead of sudo-ing everything as yourself). 尽管我使用sudo运行了所有命令,但由于出现权限错误而将所有者和组更改为我自己的所有者和组(如果您以root身份运行命令而不是对自己进行所有操作,则不需要这样做)。
  • Ran "apt-get install dirmngr" before running apt-key as I got an error that the command did not exist. 在运行apt-key之前跑了“ apt-get install dirmngr”命令,因为我收到一条命令不存在的错误消息。
  • Added the --allow-unauthenticated flag to the "apt-get install openjdk-8-jdk -y" command. 在“ apt-get install openjdk-8-jdk -y”命令中添加了--allow-unauthenticated标志。

Here are the actual commands I was able to use to successfully install the Java 8 Open JDK: 这是我用来成功安装Java 8 Open JDK的实际命令:

# Grant yourself permission to the necessary directory
sudo chown $YOUR_USER_NAME /etc/apt/sources.list.d 
sudo chgrp $YOUR_GROUP_ID /etc/apt/sources.list.d

sudo echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list

sudo echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list

sudo apt-get install dirmngr       
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update

sudo apt-get install openjdk-8-jdk -y --allow-unauthenticated

For the Oracle Java 8 JDK: 对于Oracle Java 8 JDK:

# Grant yourself permission to the necessary directory
sudo chown $YOUR_USER_NAME /etc/apt/sources.list.d 
sudo chgrp $YOUR_GROUP_ID /etc/apt/sources.list.d

sudo echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list

sudo echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list

sudo apt-get install dirmngr 
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update

sudo echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo apt-get install oracle-java8-installer -y --allow-unauthenticated

At this point, if all went as intended, the following commands should produce something that looks a lot like: 此时,如果所有操作均按预期进行,则以下命令应产生类似于以下内容的内容:

$ javac -version
javac 1.8.0_171

$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

Good luck and please let me know if this works for you. 祝您好运,如果适合您,请告诉我。 If not, I'd be happy to assist you further as needed. 如果没有,我很乐意根据需要进一步为您提供帮助。

Eric 埃里克

This one-line command successfully installed java 8 for me.这个单行命令为我成功安装了 java 8。

sudo apt install openjdk-8-jre-headless

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 AWS EC2 实例上安装 apt-get? - How to install apt-get on AWS EC2 instance? 重命名 Google Compute Engine VM 实例 - Rename Google Compute Engine VM Instance 如何移植谷歌计算引擎实例? - How to port forward Google Compute Engine Instance? “冻结”谷歌计算引擎实例 PostgreSQL - "frozen" Google compute engine instance with PostgreSQL 无法从 EC2 实例执行 sudo apt-get 更新 - Unable to perform sudo apt-get update from EC2 instance 构建自定义 Google Cloud Workstation 映像时无法找到 package apt-get - Unable to locate package apt-get when building a custom Google Cloud Workstation image 在 Ubuntu 18.04 LTS 上安装 Google Cloud SDK 后,apt-get 坏了 - Apt-get is broken after install Google Cloud SDK on Ubuntu 18.04 LTS 无法 SSH 进入我在 Google Cloud 上的 Compute Engine 虚拟机实例 - Unable to SSH into my Compute Engine VM instance on Google Cloud Google Compute Engine:所需的“compute.zones.get”权限错误 - Google Compute Engine: Required 'compute.zones.get' permission error 在 aws ec2 中,sudo: apt-get: command not found 错误 - In aws ec2, sudo: apt-get: command not found error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM