Recently, I became curious as to whether it was possible to delete the default OpenJDK 7 JRE and switch to totally using Oracle's Java - including using Oracle's Java plugin for Firefox. This blog describes my experience with this effort, and the short answer is "Yes - it is possible". Here is how:
STEP 1: First you have to download the latest version of Oracle's Java SE (aka JDK) package and install it. To do this, first point your Firefox web browser to the Oracle SE download page here and download the latest version of the 64-bit JDK (not Server JRE or the JRE) - currently at version 8u31 (or 1.8.0_31). It is also recommended that you download the API docs and demos (+samples) for the JDK - although this is not required for Java program development. Once the packages have been downloaded, close the Firefox web browser and execute the following commands:
cd Downloads
tar xzvf jdk-8u31-linux-x64.tar.gz
tar xzvf jdk-8u31-linux-x64-demos.tar.gz
unzip jdk-8u31-docs-all.zip -d jdk1.8.0_31
sudo mv jdk1.8.0_31/ /usr/lib/jvm/
sudo chown -R root:root /usr/lib/jvm/jdk1.8.0_31
cd ~
The above steps will uncompress the files downloaded to a 'jdk1.8.0_31' directory in the 'Downloads' folder. The 'jdk1.8.0_31' directory will then be moved to /usr/lib/jvm, where all the current Java files reside. The owner:group will then be set to 'root'.
WARNING: If you do not move the 'jdk1.8.0_31' directory to /usr/lib/jvm directory now, then the /usr/lib/jvm directory will be removed when you remove OpenJDK 7 later.
STEP 2: Then we have to remove the IcedTea plugin from Firefox. If you launch Firefox now, and type "about:plugins" in the location (URL) bar, it will show that 'IcedTea-Web Plugin (using IcedTea-Web 1.5 (1.5-1ubuntu1))' is one of the plugins installed. It will not be possible to remove this plugin using Firefox's -> Tools -> Add-ons as this plugin was installed by OpenJDK itself. So we have to turn to the Synaptic Packet Manager to do the job. Make sure that Firefox is closed, then launch Synaptic and enter 'icedtea' into the search box. Then mark the following items for complete removal:
icedtea-7-plugin
icedtea-plugin
icedtea-7-jre-jamvm
icedtea-netx
icedtea-netx-common
Click the 'Apply' button to remove the marked files. You can then check whether the Firefox Java plugin has been removed by launching Firefox and typing "about:plugins" in the location (URL) bar. The resulting display should indicate that there is no Java plugin present now. Then close Firefox again. A quick look into the /etc/alternatives directory will also show that the 'itweb-settings', 'jexec' and 'mozilla-plugin.so' files has also been removed.
STEP 3: Now we will replace Firefox Java plugin by Oracle's version. Let me stress that this step is optional - if you wish to test Java applets in Firefox, go ahead and install this plugin - else just ignore this step.
First check whether there is a sub-directory called 'plugins' under the '.mozilla' directory (a hidden directory - hence the period before the name) in your home directory. The 'ls -la .mozilla' command is used to perform this check.
If this directory is not present then create the directory by executing the 'mkdir .mozilla/plugins' command within your home directory. Once this directory is present, its time to create a link to Oracle's Java plugin. The name of this plugin is 'libnpjp2.so' and is found in the /usr/lib/jvm/jdk1.8.0_31/jre/lib/amd64 directory. Execute the following commands:
cd .mozilla/plugins
ln -s /usr/lib/jvm/jdk1.8.0_31/jre/lib/amd64/libnpjp2.so .
cd ~
Do not forget to include the period (.) in the second last command above. It denotes that the link will be created in the current directory (.mozilla/plugins). Once this link is created, launch Firefox again, type 'about:plugins' in the location box and the resulting display will show that Oracle's Java plugin is present. Also, if you click on Tools -> Add-ons, followed by selecting the 'Plugins' tab, you will see that the Java plugin is present.
STEP 4: Launch Synaptic again and this time, type 'openjdk' into the search box. Now mark the following files for complete removal:
default-jre
default-jre-headless
openjdk-7-jre
openjdk-7-jre-headless
openjdk-7-jre-lib
Click the 'Apply' button to remove the marked files. If you look into the /usr/lib/jvm directory, you will find that there is now just one directory there - the one containing Oracle's Java. The files in the /etc/alternatives directory will no longer contain links to Java.
NOTE: If you have set up links previously, you can now remove those links using the 'update-alternatives --remove-all itemname' (where itemname is the name of the Java link you wish to remove). Just make sure that you only remove the Java related links - removing other non-Java links may harm the whole system. It is safe to remove these links as there is one Java installed - Oracle's SE 8. The list of the files are:
java
javaws
keytool
orbd
pack200
policytool
rmid
rmiregistry
servertool
tnameserv
unpack200
STEP 5: Now we have to set the environment variables and paths correctly for the whole system. If you have already set these variables previously, then you can safely skip this step. If not, execute the following command:
sudo nano /etc/profile
This will execute the nano text editor and open the /etc/profile file for editing. Now add the following lines at the end of the file.
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_31
export PATH=$PATH:$JAVA_HOME/bin
Save the file and close it. Note that, upon system startup, these will set the JAVA_HOME and PATH environment variables for the whole system. The JAVA_HOME environment variable points to the JDK root while the PATH environment variable will add the /bin directory of the JDK to whatever path that has already been specified. This will enable the 'javac' command to be executed from any directory. Now log out and then log in again to the system in order to make sure that both the environment variables are set.
STEP 6: Check that you have correctly installed Oracle Java by executing the commands:
echo $JAVA_HOME
echo $PATH
java -version
javac -version
If you see the string 'jdk1.8.0_31' in the output to the above commands, then you have successfully removed OpenJDK 7 JRE and replaced it with Oracle SE 8.
Now whenever Oracle issue an updated version, all you have to do in order to use the new version of Java SE is to follow STEP 1, STEP 3 and STEP 5 above. Just make sure that you change the version number to the new version in the commands. No more messing around with 'update-alternative' commands - and that alone make this whole exercise worthwhile. Happy computing!
Showing posts with label OpenJDK 7 removal. Show all posts
Showing posts with label OpenJDK 7 removal. Show all posts
Thursday, January 29, 2015
Sunday, December 28, 2014
How To Remove OpenJDK 7 From Ubuntu 14.04
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.
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.
Subscribe to:
Posts (Atom)

