After reading my previous article on installing Oracle Java on Ubuntu 14.04, one of my college asked me how to remove OpenJDK 7 from his Ubuntu system. After helping him out, I realize that the process may be useful to people in the same situation. For example, if you do get a warning from Android Studio similar to the one shown below, then it's time to remove OpenJDK 7 and install Oracle's JDK 8 in its place. For instruction on how to install Oracle's JDK 8, see my blog here.
First, check for all Java installed (just in case) by executing the following command in a terminal.
sudo update-alternatives --config java
If you see a response such as the one shown below, then there is only one Java installed.
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Nothing to configure.
As a safety check, execute the following also:
sudo update-alternatives --config javac
Again, if you see something similar to the one shown below, then there is also one java compiler installed.
There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
Nothing to configure.
To list out all the Java packages already installed, execute the following command:
sudo dpkg --list | grep -i jdk
The listing will show all the OpenJDK packages that you need to remove. To list our all the JRE packages, execute the following command:
sudo dpkg --list | grep -i jre
To actually remove all the installed OpenJDK packages, you can either use a terminal and execute the proper commands, or, if you have Synaptic installed on your system, use it to remove the installed packages. Of these 2 methods, using Synaptic will be described first.
Launch Synaptic and then type 'openjdk' in the Quick filter text box. A screen similar to the one below (the screen has been expanded for clarity) will appear. Click on each of the green box to the left of each item you want removed and select 'Mark for Complete Removal'. Should you get an additional window pop-up asking you to mark additional packages, click on the 'Mark' button. When everything is done, click on the 'Apply' button. Another window will pop up - click on the 'Apply' button and the removal process will begin. Close Synaptic when done.
To remove OpenJDK using the command line in a terminal, open a terminal and execute:
sudo apt-get purge openjdk*
Enter your password if prompted, and then press the Enter key to accept the the default of 'Yes'. The OpenJDK packages will all be purged from the system. You can dos a quick check by using the commands:
sudo dpkg --list | grep -i jdk
sudo dpkg --list | grep -i jre
These 2 commands will return nothing, indicating that all OpenJDK related packages has been removed.
That's it - to download and install Oracle JDK 8, follow the instructions in my previous blog.
Thank you. It worked for me.
ReplyDeleteMe too. Thanks sire!
ReplyDeleteGreat !
ReplyDeleteWorked great, needed this to keep a single Oracle JDK installation on my system.
ReplyDeleteThank you for this guide! Worked perfectly :-)
ReplyDeleteIts simple and excellent post, worked for me. Thanks sir.
ReplyDeleteThanks. I've used these instructions about 5 times now. A real life-saver.
ReplyDeleteNice guide. It is appreciated.
ReplyDeletethanks :)
ReplyDeleteThanks a lot:-) worked for me..
ReplyDelete