I came across this because I am working through an instructional book for android programming which wants to use a specific Java SE and JRE (8u121) and requests that all other java packages be removed before continuing with the installation. So after reading the above ideas I went with:
sudo apt-get remove openjdk*
and the result was:
bryan@kali:~$ java -version
bash: /usr/bin/java: No such file or directory
So the above suggests that there is no java found of any version. Which is the OP wanted to do (I think).
In case somebody finds this thread because they are uninstalling Java so that they can install an Old Version, I have included a walk-through I found. The first two codes help you install it if you had no GUI. If you have a tarball then skip those. The last codeblock has some parts that you'll need to edit if you are not installing my same version.
In case that you are attempting to install Java JDK remotely and have absolutely no access to Graphical User Interface and web browser use the following curl method to download Java JDK using a command line.
First, obtain a correct download URL by using the curl command:
$ curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html | grep "otn-pub" | cut -d \" -f12
The above command outputs a bunch of URLs for your selection. To initiate the download of the desired Java file, copy its URL and start the download using the curl command while accepting the requested Jave license. For example:
$ curl -LOb "oraclelicense=a" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz
Install Java JDK
At this stage, we should have an appropriate Java JDK tarball within our current working directory:
Create a target Java JDK installation directory:
# mkdir /opt/java-jdk
Extract the previously downloaded Java JDK tarball:
# tar -C /opt/java-jdk -zxf jdk-8u121-linux-x64.tar.gz
Set Oracle Java as default
Currently, the system does not recognise our Java JDK installation:
$ update-alternatives --list java
update-alternatives: error: no alternatives for java
bash: java: command not found
Use the update-alternatives command to inlcude both, java and javac as part of the system's Java environment.Please replace the below path to java binaries where appropriate to reflect your downloaded java version:
# update-alternatives --install /usr/bin/java java /opt/java-jdk/jdk1.8.0_121/bin/java 1
update-alternatives: using /opt/java-jdk/jdk1.8.0_121/bin/java to provide /usr/bin/java (java) in auto mode
# update-alternatives --install /usr/bin/javac javac /opt/java-jdk/jdk1.8.0_121/bin/javac 1
update-alternatives: using /opt/java-jdk/jdk1.8.0_121/bin/javac to provide /usr/bin/javac (javac) in auto mode
Okay so after I followed that I wanted to confirm that it works...
bryan@kali:~/Desktop$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
That's it! That's what we want.
Then I became concerned that it 'apt update' may just undo what I did by updating the package (unsure). So I put them on hold. To remove hold: apt-mark unhold.
bryan@kali:~/Desktop$ sudo apt-mark hold openjdk-8*
openjdk-8-jre set on hold.
openjdk-8-jre-headless set on hold.
openjdk-8-doc set on hold.
openjdk-8-jdk set on hold.
openjdk-8-dbg set on hold.
openjdk-8-demo set on hold.
openjdk-8-jdk-headless set on hold.
openjdk-8-source set on hold.
openjdk-8-jre-dcevm set on hold.
openjdk-8-jre-zero set on hold.