Ubuntu: OpenJDK 8 - Unable to locate package
UPDATE: installation without root privileges below
I advise you to not install packages manually on ubuntu system if there is already a (semi-official) repository able to solve your problem. Further, use Oracle JDK for development, just to avoid (very sporadic) compatibility issues (i've tried many years ago, it's surely better now).
Add the webupd8 repo to your system:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Install your preferred version of jdk (versions from java-6 to java-9 available):
sudo apt-get install oracle-java8-installer
You can also install multiple version of jdk, mixing openjdk and oracle versions.
Then you can use the command update-java-alternatives to switch between 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 have software-properties-common
installed:
sudo apt-get install software-properties-common
If you're using an older version Ubuntu:
sudo apt-get install python-software-properties
JDK installation without root privileges
If you haven't administrator rights on your target machine your simplest bet is to use sdkman
to install the zulu certified openjdk:
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java
NOTE: sdkman allow to install also the official Oracle JDK, although it's not a the default option. View available versions with:
sdk ls java
Install the chosen version with:
sdk install java <version>
For example:
sdk install java 9.0.1-oracle
Glossary of commands
sudo
<command> [command_arguments]
: execute a command with the superuser privilege.add-apt-repository
<PPA_id>
: Ubuntu (just like every Debian derivatives and generally speaking every Linux distribution) has a main repository of packages that handle things like package dependencies and updating. In Ubuntu is possible to extend the main repository using a PPA (Personal Package Archive) that usually contains packages not available in the system (just like oracle jdk) or updated versions of available ones (example: LibreOffice 5 in LTS is available only through this PPA).apt-get
[install|update|upgrade|purge|...]
: it's "the" command-line package handler used to manipulate the state of every repository on the system (installing / updating / upgrading can be viewed as an alteration of the repository current state).
In our case: with the command sudo add-apt-repository ppa:webupd8team/java
we inform the system that the next repository update must retrieve packages information also from webupd8 repo.
With sudo apt-get update
we actually update the system repository (all this operations requires superuser privileges, so we prepend sudo to the commands).
sudo apt-get install oracle-java8-installer
update-java-alternatives (a specific java version of update-alternatives): in Ubuntu several packages provides the same functionality (browse the internet, compile mails, edit a text file or provides java/javac executables...). To allows the system to choose the user favourites tool given a specific task a mechanism using symlinks under
/etc/alternatives/
is used. Try to update the jdk as indicated above (switch between java 7 and java 8) and view how change the output of this command:ls -l /etc/alternatives/java*
In our case: sudo update-java-alternatives --set java-8-oracle
update symlinks under /etc/alternatives to point to java-8-oracle executables.
Extras:
man
<command>
: start using man to read a really well written and detailed help on (almost) every shell command and its options (every command i mention in this little answer has a man page, tryman update-java-alternatives
).apt-cache
search <search_key>
: query the APT cache to search for a package related with the search_key provided (can be the package name or some word in package description).apt-cache
show <package>
: provides APT information for a specific package (package version, installed or not, description).
Cannot install OpenJDK 8 on Ubuntu 18.04
Oke, I've found out by myself by reading the repository documentation.
You should be able to use any of the listed mirrors by adding a line to your /etc/apt/sources.list like this:
deb http://security.ubuntu.com/ubuntu bionic-security main universe
debian apt cant find openjdk-8-jdk
add the following line to /etc/apt/sources.list
deb http://deb.debian.org/debian/ sid main
install openjdk8
//Update the repositories
$ sudo apt-get update
$ sudo apt-get install -y openjdk-8-jdk
In fact, I think it is better to search for your question first before ask.
How to install openjdk-8-jdk on Debian 10 (Buster)?
Related Topics
How to Connect via Https Using Jsoup
How to Create a Bks (Bouncycastle) Format Java Keystore That Contains a Client Certificate Chain
Opening a Shell and Interacting with Its I/O in Java
Java Embedded Databases Comparison
How to Instantiate an Inner Class with Reflection in Java
Junit: How to Simulate System.In Testing
How to Convert a String to an Inputstream in Java
Sending a JSON Http Post Request from Android
Error: Unable to Run Mksdcard Sdk Tool
How to Create the Directory Error
How to Connect to Ftps Server with Data Connection Using Same Tls Session
How to Convert a JSON String to a Map<String, String> with Jackson JSON
Java Method to Swap Primitives
Who Sets Response Content-Type in Spring MVC (@Responsebody)