3

Oracle hosts a page on how to install Java 1.8 from the binary

I was able to do the following -

Download the x64 tar.gz on the Oracle Downloads page.

Create my directory and move the file there

sudo mkdir /usr/local/java
sudo mv ~/Downloads/jdk-8u45-linux-x64.tar.gz .

And unpack it

sudo tar zxvf jdk-8u45-linux-x64.tar.gz

The binary itself works, because I can call it using the absolute path

> /usr/local/java/jdk1.8.0_45/bin/java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

But I can't call it standalone

> java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.6-jre-headless
 * gcj-4.7-jre-headless
 * openjdk-7-jre-headless
 * openjdk-6-jre-headless
Try: sudo apt-get install <selected package>

Even setting $JAVA_HOME as that directory didn't work. Is there a step I'm missing? Does it need to be added to my $PATH?

Edit: I'm aware I could probably install java with sudo apt-get install. I ran into some trouble there in that I wasn't able to apt-get update because of some 404 errors. I'd rather handle that as a separate question/post.

Thanks!

3
  • 1
    You need to "update-alternatives". See stackoverflow.com/questions/4579156/… Commented May 19, 2015 at 3:35
  • Thanks! That did the trick :) Basically added that whole bin directory to the end of my $PATH Commented May 19, 2015 at 3:43
  • @Thilo you can't use 'update-alternatives' here because the version is not in the path yet Commented Dec 13, 2018 at 5:27

2 Answers 2

5

You have just extracted the binary file but you didn't set JAVA_HOME. First set the JAVA_HOME in your profile i.e. in ~/.bashrc file.

export JAVA_HOME=/usr/local/java/jdk1.8.0_45
export PATH=$PATH:$JAVA_HOME/bin

Reload the ~/.bashrc file as

> source ~/.bashrc press enter

Then try again.

> java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Credit to user Thilo above for also providing/linking to the same answer.
0

The best way to do this is to use update alternatives not using JAVA_HOME. I downloaded the latest tarball jdk-8u162-linux-x64.tar.gz into a subdirectory ./src. I've also set up /opt so that it is owned by me, otherwise you need to use sudo for the untarring of the .tar.gz file.

#!/usr/bin/env bash

MAJOR_VERSION=8
ORACLE_BUILD_VERSION=162

JDK_TARBALL_VERSION=8u${ORACLE_BUILD_VERSION}-linux-x64
JDK_VERSION=1.${MAJOR_VERSION}.0_${ORACLE_BUILD_VERSION}
PRIORITY="10${MAJOR_VERSION}1"

cd src && tar xzf jdk-${JDK_TARBALL_VERSION}.tar.gz -C /opt/jdk

sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk${JDK_VERSION}/bin/java ${PRIORITY}
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk${JDK_VERSION}/bin/javac ${PRIORITY}

echo "Checking: alternatives on java and javac"
sudo update-alternatives --display java
sudo update-alternatives --display javac

echo "Running: java -version"
java -version

I've included build 162 since this is much more recent that 45 in your message. This script above should be provided to everyone in the field of development since we can see currently that oracle-java8-installer for Debian and Ubuntu is broken as of yesterday. It might be fixed in a few days but this script will always work.

The priority value in the script is really important since you must override existing priority of the installed package. I've set it to use the major version to be installed. This priority would only fail if you have openjdk version 9 installed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.