[英]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所示代码块中,我拉出了适用的代码行,并对其进行了一些修改,如下所示:
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.