Ubuntu: OpenJDK 8 - Cannot find package

So, I just installed Ubuntu, and this is my first Linux experience, so bring my noob here.

In any case, I downloaded the Java 8 JDK directly from Oracle, but I also understand that OpenJDK for Java 8, too. I have two questions.

  • What is the difference between the version of Oracle and OpenJDK. Pros / Cons?

  • When I try to get OpenJDK 8, I can not. I am inserting a terminal command and the error message I get here, hoping to get some advice. Again, very new to Linux, was on my first Linux distribution ever in less than an hour here at this point.

    user@computer:~/Java$ sudo apt-get install openjdk-8-jdk Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package openjdk-8-jdk 

Any help would be greatly appreciated. So far, I'm just using the Oracle package. Thank.

Edit:

So now I have a new problem. I installed OpenJDK 7, it came with Maven and just installed before I realized that I was getting a two-to-one deal. I now have JDK 7, Eclipse, and Maven, and they all work, but I am stuck on JDK 7, not 8.

I saw that there is a link below, I'm going to check it in the morning, it's 2 in the morning, and I'm tired right now. Any other tips for this new issue will be appreciated, otherwise I will definitely check this link first thing in the morning.

+50
java linux ubuntu
05 Oct '15 at 5:49
source share
3 answers

UPDATE : non-root installation below




I advise you not to install packages manually on an ubuntu system if you already have a (semi-official) repository that can solve your problem. Also, use the Oracle JDK for development to avoid (very sporadic) compatibility issues (I tried many years ago, this is definitely better now).

Add the webupd8 repository to your system:

 sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 

Install your preferred jdk version (versions from java-6 to java-9 are available):

 sudo apt-get install oracle-java8-installer 



You can also install several versions of jdk, mix openjdk and oracle versions. Then you can use the update-java-alternatives command to switch between the installed version:

 # list available jdk update-java-alternatives --list # use jdk7 sudo update-java-alternatives --set java-7-oracle # use jdk8 sudo update-java-alternatives --set java-8-oracle 

Requirements

If you get add-apt-repository: command not found , be sure to set software-properties-common :

 sudo apt-get install software-properties-common 

If you are using an older version of Ubuntu:

 sudo apt-get install python-software-properties 



Install JDK without root privileges

If you do not have administrator rights on your target machine, try using sdkman to install the certified zulu openjdk:

 curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java 

NOTE. sdkman also allows you to install the official Oracle JDK, although this is not the default option. View available versions with:

 sdk ls java 

Install the selected version using

 sdk install java <version> 

For example:

 sdk install java 9.0.1-oracle 



Team Glossary

  • sudo <command> [command_arguments] : run the command with superuser privilege.

  • add-apt-repository <PPA_id> : Ubuntu (like all Debian derivatives and, generally speaking, every Linux distribution) has a main package repository that handles things like package dependencies and updates. In Ubuntu, you can expand the main repository using PPA (Personal Package Archive), which usually contains packages that are not available on the system (for example, oracle jdk) or updated versions of available (for example: LibreOffice 5 in LTS is available only through this PPA ).

  • apt-get [install|update|upgrade|purge|...] : it is a "command line package handler used to control the status of each repository in the system (installation / update / update can be viewed as a change in the current state of the repository).

In our case: using the sudo add-apt-repository ppa:webupd8team/java we tell the system that the next repository update should also receive package information from the webupd8 repository.

With sudo apt-get update we actually update the system repository (all these operations require superuser privileges, so we add sudo to the commands).

sudo apt-get install oracle-java8-installer

  • update-java-alternatives (a specific version of java alternative updates ): in Ubuntu, several packages provide the same functionality (surf the Internet, compile mail, edit a text file, or provide java / javac executables ...). In order for the system to select the tool of user favorites, taking into account a specific task, a mechanism is used using symbolic links in /etc/alternatives/ . Try updating jdk as above (switching between java 7 and java 8) and see how to change the output of this command:

    ls -l /etc/alternatives/java*

In our case: sudo update-java-alternatives --set java-8-oracle update symbolic links under / etc / alternatives to point to java-8-oracle executables.

Additionally:

  • man <command> : start using the person to read the very well-written and detailed help of (almost) every shell command and its parameters (each command mentioned in this small answer, man page, try man update-java-alternatives ).

  • apt-cache search <search_key> : request APT cache to search for the package associated with the provided search key (may be the name of the package or some word in the package description)

  • apt-cache show <package> : provides APT information for a specific package (package version, installed or not, description).

+78
05 Oct '15 at 8:34
source share

As you can see, I installed only java 1.7 (on a Ubuntu 14.04 machine).

 update-java-alternatives -l java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64 

To install Java 8, I did

 sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk 

Subsequently, I now have java 7 and 8,

 update-java-alternatives -l java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64 java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64 

BONUS ADDED (how to switch between different versions)

  • run the follwing command from the terminal:

sudo update-alternatives --config java

 There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode * 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 manual mode Press enter to keep the current choice[*], or type selection number: 

As you can see, I am running open jdk 8. To switch to jdk 7, press 1 and press Enter . Do the same for javac using sudo update-alternatives --config javac .

Check the versions to confirm the change: java -version and javac -version .

+58
Nov 26 '15 at 6:36
source share

I get OpenJDK 8 from the official Debian repositories, not some random PPA or proprietary Oracle binary. Here is how I did it:

sudo apt-get install debian-keyring debian-archive-keyring

Make /etc/apt/sources.list.d/debian-jessie-backports.list :

 deb http://httpredir.debian.org/debian/ jessie-backports main 

Do /etc/apt/preferences.d/debian-jessie-backports :

 Package: * Pin: release o=Debian,a=jessie-backports Pin-Priority: -200 

Then finally complete the installation:

 sudo apt-get update sudo apt-get -t jessie-backports install openjdk-8-jdk 
+11
Aug 10 '16 at 8:24
source share



All Articles