Setting $JAVA-HOME for linux(Ubuntu) users(Resolved)

Hi @devs

Lately I have been solving some small and annoying issue but still couldn’t get a solution to this. When i try to install openjdk-8-jdk (sudo apt install openjdk-8-jdk) this is what i get…

ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$ sudo apt install openjdk-8-jdk
[sudo] password for ndacyayisenga: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-8-jdk is already the newest version (8u292-b10-0ubuntu1~20.04).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$

and when i do java -version

ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$ java -version

Command 'java' not found, but can be installed with:

sudo apt install openjdk-11-jre-headless  # version 11.0.11+9-0ubuntu2~20.04, or
sudo apt install default-jre              # version 2:1.11-72
sudo apt install openjdk-13-jre-headless  # version 13.0.7+5-0ubuntu1~20.04
sudo apt install openjdk-16-jre-headless  # version 16.0.1+9-1~20.04
sudo apt install openjdk-8-jre-headless   # version 8u292-b10-0ubuntu1~20.04
sudo apt install openjdk-14-jre-headless  # version 14.0.2+12-1~20.04

I tried to set the $JAVA_HOME path by

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

and Add JAVA bin directory to the PATH variable by

export PATH=$PATH:$JAVA_HOME/bin

To my surprise is that when i also try to whereis java command returns nothing

ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$ whereis java
java:
ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$

This is annoying… could anyone try to explain to me what is happening

cc @dev1 @dev2 @dev3 @dev4 @dev5 @mozzy @ibacher @suruchi @dkayiwa @kdaud

you could try to follow Installing Open JDK on Ubuntu - YouTube

Hi @herbert24 did you read through that well?

what happens when you take on the steps in that video

Actually its what i was describing in the post… same steps but am getting weired results… And i think currently the default jdk is 11 not 1.8

Could there be something am not getting right @herbert24 ?

what does this return sudo apt install openjdk-11-jre-headless

I found jenv to be very useful to control which Java is used. You can set globally and also specify which version of Java use in a folder.

@ndacyayisenga in addition to jenv recommended you can also opt to use sudo update-alternatives --config java and then just select which java version you want to use .

Personally it works well for me to switch between java versions on my machine

@gcliff actually the problem I have is when i try to install java the machine tells me that java is already installed but when I try to check for the java version my machine doesn’t recorgnize java… @gcliff did u try to check through this below critically

error means that particular command you’re trying to invoke is not found in either of directories listed in $PATH system variable.

Specify full path when running an executable:

/opt/jdk-12345/bin/java -version

You can also peek into this

@gcliff Actually there is nothing like Java in my machine

ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$ whereis java
java:
ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$

Thats why am not even able to set the $PATH… Actually Java tells me its in the machine yet its not there… maybe any other i could install it woould help…

ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$ sudo apt install openjdk-8-jdk
[sudo] password for ndacyayisenga: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-8-jdk is already the newest version (8u292-b10-0ubuntu1~20.04).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
ndacyayisenga@ndacyayisenga-ThinkPad-S5-S540:~$

Thanks @gcliff… I was able to resolve this though the solution was so mechanical :grinning: I just got a friend with java 1.8 and copied the java related files in their right path from his computer on a flash to mine. I just found out that many of them were missing and sudo apt install openjdk-8-jdk wasn’t downloading them

2 Likes

it looks like to use 1.8 you need to first download its dependencies for ubuntu 20, 11 looks to be the default