[java] Installing jdk8 on ubuntu- "unable to locate package" update doesn't fix

I've been trying to install the jdk on my ubuntu after downloading it.

first I've used: sudo apt-get update

then: sudo apt-get install jdk* (because I didn't want to write the whole long name).

it didn't work- printed the message in the title.

I thought the problem might me with the directory I'm executing from (I've executed it from the Downloads directory in which the file exists), so I've tried executing the same command (sudo apt-get install jdk*) from the home directory (root directory). Then it worked.. the whole installation took about 5 minutes and it looked like it was installing a lot of things I didn't ask for.

I wasn't sure it installed what I needed to I went back to the Downloads directory where the jdk8 package was located and like the first time ran the command from there. the same message as before... couldn't locate the package.

What have I done wrong ? Obviously it wasn't installed because when I've checked the version of java (java -version) it didn't show jdk8 was installed.

Thank you if you've taken the time to read to this point :)

This question is related to java linux

The answer is


I used another repository for oracle java.

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

sudo apt install  oracle-java11-installer

It's same as vikasdumca's steps, but thought to share the link.

run the following command

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

then

sudo apt-get install oracle-java8-installer

this would install oracle java 8 on ubuntu properly.

find it from this post

you can find more info on "Managing Java" or "Setting the "JAVA_HOME" environment variable" from the post.


Ubuntu defaults to the OpenJDK packages. If you want to install Oracle's JDK, then you need to visit their download page, and grab the package from there.

Once you've installed the Oracle JDK, you also need to update the following (system defaults will point to OpenJDK):

export JAVA_HOME=/my/path/to/oracle/jdk
export PATH=$JAVA_HOME/bin:$PATH

If you want the Oracle JDK to be the default for your system, you will need to remove the OpenJDK packages, and update your profile environment variables.


In my case:

sudo -E add-apt-repository ppa:linuxuprising/java

sudo apt-get update

sudo apt install  oracle-java12-installer

that works fine


For me non of the above worked and I had to do as below, and it worked,

sudo -E add-apt-repository ppa:openjdk-r/ppa

and then,

sudo apt-get update

sudo apt-get install openjdk-8-jdk

Reference: https://askubuntu.com/questions/644188/updating-jdk-7-to-8-unable-to-locate-package


Command Line option - Ubuntu

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Then in terminal

sudo apt-get install oracle-java8-installer

When there are multiple Java installations on your System, the Java version to use as default can be chosen. To do this, execute the following command.

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Edit - Manual Java Installation

Download oracle jdk

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Extract zip into desired folder

 e.g  /usr/local/  after extract /usr/local/jdk1.8.0_65

Setup

sudo update-alternatives --install  /usr/bin/java java /usr/local/jdk1.8.0_65/bin/java 1
sudo update-alternatives --install  /usr/bin/javac javac /usr/local/jdk1.8.0_65/bin/javac 1
sudo update-alternatives --install  /usr/bin/javaws javaws /usr/local/jdk1.8.0_65/bin/javaws 1

sudo update-alternatives --set  java /usr/local/jdk1.8.0_65/bin/java
sudo update-alternatives --set  javac /usr/local/jdk1.8.0_65/bin/javac
sudo update-alternatives --set  javaws /usr/local/jdk1.8.0_65/bin/javaws

Edit /etc/environment set JAVA_HOME path for external applications like Eclipse and Idea


If you get a

sudo: add-apt-repository: command not found

then you need to run the following command

sudo apt-get install software-properties-common python-software-properties


For those who had trouble with the apt-get, or with the long instruction. I solved it in a relatively painless way.

  1. Download the installer from here, or direct download link
  2. $ sudo dpkg -i oracle-java8-installer_8u51+8u51arm-1-webupd8-0_all.deb