web-dev-qa-db-ja.com

apt-getを使用してGoogleComputeEngineインスタンスにJava 8をインストールする

このコマンドをapt-getで実行しましたが、このエラーが発生しました。これを解決する方法がよくわかりません。これは私がapt-getを使用して、不可能なことを求めて犯した重大な間違いですか?インストールを妨げる根本的な原因を誰かが理解していますか?

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.
7
Alex Amato

ワンライナーです

Sudo apt-get -y install default-jdk
Java -version
4
Vincent

Google ComputeEngineインスタンスの1つにJava 8 JDKをインストールしようとすると、同様の問題が発生し、ここで解決策を見つけました(ただし、最初に以下の変更について読んでください)。

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

「スクリプトのデプロイ」セクションで、install.shに示されているコードブロック内で、該当する行を引き出し、次のようにいくつかの変更を加えて実行しました。

  • 私はすべてのコマンドをSudoで実行しましたが、コマンドを実行する前に、彼と同じように「su-」(ルートに変更)する方がおそらく適切でしょう。
  • Sudoですべてのコマンドを実行したにもかかわらずアクセス許可エラーが発生したため、所有者とグループを自分のものに変更しました(すべてを自分でSudoするのではなく、rootとしてコマンドを実行する場合はこれを行う必要はありません)。
  • コマンドが存在しないというエラーが表示されたため、apt-keyを実行する前に「apt-getinstalldirmngr」を実行しました。
  • 「apt-getinstallopenjdk-8-jdk-y」コマンドに--allow-unauthenticatedフラグを追加しました。

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

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

この時点で、すべてが意図したとおりに進んだ場合、次のコマンドは次のようなものを生成するはずです。

$ 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)

頑張って、これがあなたのために働くかどうか私に知らせてください。そうでない場合は、必要に応じてさらにサポートさせていただきます。

エリック

1
Eric Green