5

I have an ubuntu VM, where i by accident installed jdk 11, but i wanted to install jdk 8, and then set the enviroment variable like this.

#in the .bashrc file if want to add the following lines
export JAVA_HOME=~/java/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH
export SPTARGET=sandbox 

the problem is that i did not install the jdk, i did it directly from the command line

sudo apt install default-jre

and whenever i check the version with

$ java -version outputs: openjdk version "11.0.3" 2019-04-16

does anybody know how i can remove this java version, and then add the java jdk environment variable manually?

2 Answers2

7

I know how :)

Uninstall Java first (choose one of these three) :

you can type the following into your terminal :

sudo apt purge default-jre

if this is not a removable package (although it should be since that's what you installed) then run this instead :

sudo apt purge openjdk*

if this is still not it then this must be it :

sudo apt purge oracle-java*

Then reinstall the Java version you want :

sudo add-apt-repository ppa:openjdk-r/ppa -y
sudo apt update
sudo apt install openjdk-8-jdk openjdk-8-jre

there java 8 jdk is now installed.

it now no longer possible (at all, to my knowledge, please correct me if not) to install oracle's version of java 8 (and especially not 9) jdk on ubuntu.

tatsu
  • 3,107
2

Run sudo update-alternatives --config java
Select java version you want then check java -version again.

Sy Tran
  • 121