I have tried sudo apt-get autoclean and sudo apt-get clean. Still I keep getting this error

I am running Ubuntu 12

siddharth@IWORKHERE:~/Downloads$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree        
Reading state information... Done 
Correcting dependencies... Done 
The following extra packages will be installed:   
Suggested packages:  
The following packages will be upgraded:   
      openjdk-7-jdk 1 upgraded, 0 newly installed, 0 to remove and 89 not upgraded. 
Need to get 0 B/16.5 MB of archives. 
After this operation, 88.1 kB of additional disk space will be used. 
Do you want to continue [Y/n]? Y 
(Reading database ... 394130 files and directories currently installed.) 
Preparing to replace openjdk-7-jdk 7u55-2.4.7-1ubuntu1~ (using .../openjdk-7-jdk_7u65-2.5.1-4ubuntu1~ ... 
Unpacking replacement openjdk-7-jdk ... dpkg: error processing 
/var/cache/apt/archives/openjdk-7-jdk_7u65-2.5.1-4ubuntu1~ (--unpack):  
trying to overwrite '/usr/lib/jvm/java-7-openjdk-i386/src.zip', which is also in package openjdk-7-source 7u55-2.4.7-1ubuntu1~ 
Errors were encountered while processing:  /var/cache/apt/archives/openjdk-7-jdk_7u65-2.5.1-4ubuntu1~ E: Sub-process /usr/bin/dpkg returned an error code (1)

2 Answers 2

sudo dpkg -r openjdk-7-jdk
sudo apt-get remove --purge openjdk-7-jdk
sudo apt-get autoremove
sudo apt-get clean
sudo apt-get update

then finally, you are set to install that package as if it's a fresh without any trailing history of the installation.

  • This worked for me when the tomcat7 installation with apt-get failed.
    – dr jerry
    Nov 29, 2014 at 16:45

You will need to force over write of that file.

please run this command sudo dpkg -i --force-overwrite /var/cache/apt/archives/openjdk-7-jdk_7u65-2.5.1-4ubuntu1~

then run sudo apt-get -f install

ref: [SOLVED] Error ‘dpkg: error processing (--unpack) trying to overwrite…

  • This may cause trouble e.g. when there's an update for that package. If the two files don't have the same content the program may not work as expected. Oct 8, 2014 at 15:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.