Ubuntu 18.04 Java Command Not Found Despite Being Installed

17.3k Views Asked by At

I initially had default-jdk and default-jre installed on Ubuntu 18.04.

Attempted to host a Minecraft Server for a friend, but was given the error found here

I followed the commentor's advice to reinstall java version 8 rather than version 11 installed above, by following this advice here that being

sudo rm -r /usr/lib/jvm/java-11-oracle

but as a mistake I had removed all files in that folder, leaving just the two directories

  1. java-11-openjdk-amd64
  2. java-8-openjdk-amd64

since then I have attempted to reinstall java using sudo apt-get install default-jdk ; sudo apt-get install default-jre and they install just fine, but running java -version, either as root or as user, returns:

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

  1. sudo apt install default-jre
  2. sudo apt install openjdk-11-jre-headless
  3. sudo apt install openjdk-8-jre-headless

I have scoured askubuntu, digitalocean, and stackoverflow for some answers but I can't find anything that fixes this problem. I also asked my roommate, who is an experienced Computer Science major and who has used ubuntu extensively in the past, and he couldn't find a solution. Has anyone encountered this issue before?

I appreciate any and all responses

2

There are 2 best solutions below

0
On

Solution has been found. Running:

sudo apt purge -y openjdk-11-jre-headless
sudo apt purge -y openjdk-8-jre-headless
sudo apt purge -y default-jdk

and reinstalling has resolved the issue

1
On

Check your path. You should have remove the old jdk using apt-get. I think your system still assumes the old jdk-11 is still present. You could try to re-install it or use update-alternatives to switch to the other version.