Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I ran this command with apt-get but have received this error. I am not too sure how to resolve this. Is this come core mistake I have made using apt-get, asking for something impossible? 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.
like image 749
Alex Amato Avatar asked Jun 19 '18 01:06

Alex Amato


People also ask

What is a Google Compute Engine instance?

An instance is a virtual machine (VM) hosted on Google's infrastructure. You can create an instance or create a group of managed instances by using the Google Cloud console, the Google Cloud CLI, or the Compute Engine API.


2 Answers

It's a one liner

sudo apt-get -y install default-jdk
java -version
like image 61
Vincent Avatar answered Oct 24 '22 10:10

Vincent


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

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:

  • 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.
  • 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).
  • Ran "apt-get install dirmngr" before running apt-key as I got an error that the command did not exist.
  • Added the --allow-unauthenticated flag to the "apt-get install openjdk-8-jdk -y" command.

Here are the actual commands I was able to use to successfully install the 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:

# 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

like image 21
Eric Green Avatar answered Oct 24 '22 09:10

Eric Green