8

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.
Alex Amato
  • 1,685
  • 10
  • 15
  • 2
    https://unix.stackexchange.com/questions/326377/install-jdk-8-on-debian https://serverfault.com/questions/830636/cannot-install-openjdk-8-jre-headless-on-debian-jessie/ – Kara Jun 19 '18 at 15:09

3 Answers3

10

It's a one liner

sudo apt-get -y install default-jdk
java -version
Vincent
  • 1,553
  • 1
  • 11
  • 21
3

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

Eric Green
  • 1,151
  • 9
  • 17
-1

This one-line command successfully installed java 8 for me.

sudo apt install openjdk-8-jre-headless

YGao
  • 59
  • 1
  • 3