get rid of Half-installed java installation on ubuntu

I installed java by downloading the RPM file from java.com (1.8.0-71) and used alien to generate a .deb file which i installed. It failed and I can't remove it anymore.

If I try to use apt-get I always get a note that I should reinstall the package (if it was that easy):

faustdonner@v22015113109829193:~$ sudo dpkg -i jre1.8.0-71_1.8.071-1_amd64.deb
Previously not selected package jre1.8.0-71 is selected.
(Reading database ... 84902 files and directories currently installed.)
Preparation for unpacking jre1.8.0-71_1.8.071-1_amd64.deb ...
Unpacking jre1.8.0-71 (1.8.071-1) through (1.8.071-1) ...
/var/lib/dpkg/info/jre1.8.0-71.postrm: Line 586: /usr/sbin/alternatives:  
 File or directory not found  
dpkg: warning: subprocess old post-removal script returned error exit status 127
dpkg: instead script is trying the new package ...
find: "/usr/java/*": File or directory not found
/var/lib/dpkg/tmp.ci/postrm: Line 586: /usr/sbin/alternatives:
 File or directory not found   
dpkg: error processing the archive jre1.8.0-71_1.8.071-1_amd64.deb (--install):
Subprocess new post-removal script returned error exit status 127
/var/lib/dpkg/tmp.ci/postrm: Line 586: /usr/sbin/alternatives:  
 File or directory not found  
dpkg: error while cleaning up:
 Subprocess new post-removal script returned error exit status 127
Errors were encountered while processing:
 jre1.8.0-71_1.8.071-1_amd64.deb

When i try to force-purge:

faustdonner@v22015113109829193:~$ sudo dpkg --force-all --purge jre1.8.0-71  
dpkg: warning: Problem is skipped because --force is specified:
dpkg: warning: Package is in a very bad inconsistent state; you should
reinstall it before attempting to remove it.
(Reading database ... 84902 files and directories currently installed.)
Removing jre1.8.0-71 (1.8.071-1) ...
/var/lib/dpkg/info/jre1.8.0-71.postrm: Line 586: /usr/sbin/alternatives:  
 File or directory not found  
dpkg: error processing the packet jre1.8.0-71 (--purge):
 Subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 jre1.8.0-71_1.8.071-1_amd64.deb

The second line says its in an very bad inconsistent state. It tries to access folders which it has not yet created so it fails at everything I tried. Can I maybe delete the entry of the installation in the dpkg so it is as if I never installed it? I don't care anymore if it is super clean, I just want to be able to use apt-get again.


Solution 1:

reinst-required
A package marked reinst-required is broken and requires reinstallation. These packages cannot be removed, unless forced with option --force-remove-reinstreq.

Open the terminal and type:

sudo dpkg --remove --force-remove-reinstreq jre1.8.0-71  
sudo apt install openjdk-7-jre # install jre from the default Ubuntu repositories