For me it was:
sudo apt-get remove openjdk-6*
sudo apt-get remove icedtea*
Answer from DavidGamba on Stack ExchangeFor me it was:
sudo apt-get remove openjdk-6*
sudo apt-get remove icedtea*
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.
{begin copy/paste}
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:
$ ls
jdk-8u121-linux-x64.tar.gz
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
$ 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
{end copy/paste}
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.
How to uninstall versions of Java openJDK - Unix & Linux Stack Exchange
linux - How to remove old version of Java and install new version - Stack Overflow
how to remove default-jre java installation from Ubuntu? - Stack Overflow
help me uninstall java that is installed and work but not uninstallable by apt or snap???
Videos
Remove all the Java related packages (Sun, Oracle, OpenJDK, IcedTea plugins, GIJ):
dpkg-query -W -f='${binary:Package}\n' | grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e '^java-common' | xargs sudo apt-get -y remove sudo apt-get -y autoremovePurge config files (careful. This command removed libsgutils2-2 and virtualbox config files too):
dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purgeRemove Java config and cache directory:
sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rfRemove manually installed JVMs:
sudo rm -rf /usr/lib/jvm/*Remove Java entries, if there is still any, from the alternatives:
for g in ControlPanel java java_vm javaws jcontrol jexec keytool mozilla-javaplugin.so orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 appletviewer apt extcheck HtmlConverter idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc xulrunner-1.9-javaplugin.so; do sudo update-alternatives --remove-all $g; doneSearch for possible remaining Java directories:
sudo updatedb sudo locate -b '\pack200'If the command above produces any output like
/path/to/jre1.6.0_34/bin/pack200remove the directory that is parent of bin, like this:sudo rm -rf /path/to/jre1.6.0_34.
To completely remove OpenJDK on Ubuntu 11.10 (this may or may not be sufficient on other versions of Ubuntu), run:
sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
If you want instructions for removing the proprietary Oracle ("Sun") version of Java, then you'll have to specify how you installed it. (If you edit your question to indicate this and leave a comment to this answer, I'll try to add information about how to remove that too.)
The unwanted versions can be removed by name:
sudo apt remove openjdk-8-jdk
sudo apt remove openjdk-11-jdk
They are installed with different packages.
You can see all the openjdk packages available with this command:
sudo apt update
apt-cache search openjdk
You can see all openjdk packages in your system with:
dpkg -l | grep openjdk
Note: I am a RedHat user, not a Mint expert but this is pretty much the same on every distro. I just checked the package names on Mint for those commands to work.
With the provided instructions I was able to uninstall everything I don't need. I also had to uninstall headless versions separately with commands:
sudo apt remove openjdk-8-jre-headless
sudo apt remove openjdk-11-jre-headless
To remove OpenJDK (the one you've already installed)
sudo apt-get purge openjdk-\*Make a new directory for your new JDK
sudo mkdir -p /usr/local/javaCopy the file to the directory (you should be in that file path)
sudo cp -r jdk-8u45-linux-x64.tar.gz /usr/local/java/Extract the file
sudo tar xvzf jdk-8u45-linux-x64.tar.gzYou should add this to your PATH now. To do that:
a. Open /etc/profile :
sudo gedit /etc/profileb. Scroll down (the end) and add the path where your jdk was installed
JAVA_HOME=/usr/local/java/jdk1.8.0_45 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export PATHSave and exit
Inform your Linux system where your Oracle Java JDK/JRE is located.
a. Notify the system that Oracle Java JRE is available for use
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_45/bin/java" 1b. Notify the system that Oracle Java JDK is available for use
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_45/bin/javac" 1c. Notify the system that Oracle Java Web start is available for use
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1Inform your Linux system that Oracle Java JDK/JRE must be the default Java.
a. Set the java runtime environment for the system
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_45/bin/javab. Set the javac compiler for the system
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_45/bin/javacc. Set Java Web start for the system
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_20/bin/javawsReload your system wide PATH
source /etc/profileCheck the new version and you're done!
java -version
Just unpack the new Java version, for example into /opt. Then do
Copyexport JAVA_HOME=/opt/jdk1.8.0_45
export PATH=$JAVA_HOME/bin:$PATH
Put these exports into the startup files for your shell and you should be set. It is not necessary to uninstall the Java 7 installation.
To completely remove jdk from your system, follow these below steps:
- Type
sudo apt-get autoremove default-jdk openjdk-(Don't hitEnterright now). - Now press
tabbutton for 2 or 3 times, you will get list of packages starting withopenjdk-. - Look for name like
openjdk-11-jdk. You need to get java version, here is 11. - Now complete your command to
sudo apt-get autoremove default-jdk openjdk-11-jdk. (Change 11 to your java version) - And Hit
Enterbutton.
Now you have done removing java from your system.
sudo apt-get remove default-jre
removes the package "default-jre". all tho you should ask in askUbuntu
No need to uninstall your other java version(s) that's already installed on your machine. Whenever required, you can conveniently use the utility 'update-alternatives' to choose the Java runtime that you wish to activate. It will automagically update the required symbolic links.
You just need to run the below command, and select the version of your choice. That's all!
sudo update-alternatives --config java
/usr/bin/java is a symbolic link to /etc/alternatives/java which is in turn is a symbolic link to /usr/lib/jvm/java-11-oracle/bin/java. From this, it seems that you've downloaded and configured Oracle's Java 11. Moreover JDK doesn't appear as an standalone app in Ubuntu Software.
To get rid of that Java and install Java 8 (OpenJDK):
Remove the Oracle's Java folder:
sudo rm -r /usr/lib/jvm/java-11-oracleInstall OpenJDK 8 from APT:
sudo apt install openjdk-8-jdk openjdk-8-jreConfirm Java version using:
java -version
maxtrax@maxtrax-MS-7B89:~/Clanlord$ java -version
openjdk version "21.0.4" 2024-07-16
OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu224.04)
OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)
maxtrax@maxtrax-MS-7B89:~/Clanlord$ sudo apt purge OpenJDK
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package OpenJDK
maxtrax@maxtrax-MS-7B89:~/Clanlord$ snap remove OpenJDK
snap "OpenJDK" is not installed