Install & Uninstall Java

Install Java

NOTE: if you want to develop to Android then:

  1. install an 64bit version
  2. install Oracle Java as shown below

You can use 32bit but it does not worth it.

OpenJava

If you want the default (OpenJava) then:

  1. sudo apt-get update
  2. sudo apt-get install default-jre
  3. sudo apt-get install default-jdk

Oracle Java

But preferably if you are going to develop in Java, install Sun version instead:

  1. sudo apt-get install python-software-properties
  2. sudo add-apt-repository ppa:webupd8team/java
  3. sudo apt-get update
  4. sudo apt-get install oracle-java7-installer            (or 8 etc)
  5. sudo update-alternatives –config java (to select default Java)

If you want to setup JAVA_HOME:

  1. sudo update-alternatives –config java
  2. From the menu above, write down the path of the version you want (eg /usr/lib/jvm/java-7-oracle)
  3. edit /etc/environment (vim, nano etc)
  4. add or update the line: JAVA_HOME=”YOUR_PATH”
  5. reload environment: source environment

Uninstall Java

If you want to completely uninstall java then:

  1. Remove packages:
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 autoremove
  1. Purge config files:
dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge
  1. Remove Java config and cache directory:
sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf
  1. Remove manually installed JVMs:
sudo rm -rf /usr/lib/jvm/*
  1. 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;
  1. Search for possible remaining Java directories:
sudo updatedb
sudo locate -b '\pack200'

And look for entries with jre or jdk and delete them

At the sidebar menu you can find links to scripts that do all those steps at once.

 

 

references:

https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get

http://askubuntu.com/questions/84483/how-to-completely-uninstall-java

Advertisements