4

Whenever I try to install, update, or do anything with apt-get, I always get a error message similar to this, griping about vim:

0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
Setting up vim (2:7.3.154+hg~74503f6ee649-2ubuntu3.1) ...
update-alternatives: error: /var/lib/dpkg/alternatives/vim corrupt: invalid status
dpkg: error processing vim (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 vim

Not exactly sure what's going on here. My assumption is that something is corrupt with vim? Here is what I've tried to fix the issue:

  1. Uninstall vim (sudo apt-get remove vim) - Removing fails and gives back an error similar to the one above.
  2. sudo apt-get purge vim - Fails, same errors.
  3. Removing the /var/lib/dpkg/alternatives/vim file mentioned in the error message and then trying remove/purge again - Removing/purging still fails, but instead of:

    update-alternatives: error: /var/lib/dpkg/alternatives/vim corrupt: invalid status
    

    In its place, I get:

    update-alternatives: error: /var/lib/dpkg/alternatives/vimdiff corrupt: line not terminated while trying to read status
    
  4. Installing vim again - Fails, same errors.

  5. sudo apt-get clean && sudo apt-get autoremove- Fails, same errors.
  6. sudo apt-get install --fix-broken - Fails, same errors.

This is getting a bit annoying. vim just won't die. What's going wrong? What am I doing wrong? How do I fix this?

Help would be greatly appreciated.

** EDIT **

As requested:

Output of LC_MESSAGES=C update-alternatives --query vim:

Link: vim
Status: auto
Best: /usr/bin/vim.basic
Value: /usr/bin/vim.basic

Alternative: /usr/bin/vim.basic
Priority: 30

content of /var/lib/dpkg/alternatives/vimdiff:

b0VIM 7.3Ýroot

Can't fetch the content of /var/lib/dpkg/alternatives/vim because I deleted it, haha sorry.

10
  • 1
    What's the content of /var/lib/dpkg/alternatives/vim and the output of LC_MESSAGES=C update-alternatives --query vim? Same for vimdiff, please. – David Foerster Dec 29 '15 at 17:17
  • @DavidFoerster I've edited the question to include the information. – MD-7 Dec 29 '15 at 19:31
  • That file is indeed corrupted. Here's what mine looks like: paste.ubuntu.com/14264045 – muru Dec 29 '15 at 19:33
  • @muru Ick, thats not right at all, haha! Yeah, it raised a red flag as soon as I saw the output. Thanks for the comparison. I just copied in the contents of your file into mine. New errors: /var/lib/dpkg/alternatives/vimdiff corrupt: unexpected end of file while trying to read master file /var/lib/dpkg/alternatives/rvim corrupt: line not terminated while trying to read status – MD-7 Dec 29 '15 at 19:40
  • @MD-7 I'm not sure copying mine was the best idea - you don't have vim.gnome, for one. For another, the paste doesn't show it, but the file has an extra, blank line at the end (one more line after 60). – muru Dec 29 '15 at 19:43
5

The alternatives entries are hopelessly broken.

  1. You should remove them with:

    sudo update-alternatives --remove-all vim
    sudo rm -f /etc/alternatives/vim /var/lib/dpkg/alternatives/vim
    

    If update-alternatives complains about corrupt files again, ignore it and just proceed to delete them with the next command.

  2. Then re-install their packages with:

    sudo apt-get install --reinstall vim
    

    This will restore the alternatives entries according to the packages available on your system.

  3. Proceed analogously for vimdiff, rvim and other corrupted entries.

3
  • This sounds promising. It's worked for the first couple files. But now I run sudo update-alternatives --remove-all rvim and I get this error message: update-alternatives: error: /var/lib/dpkg/alternatives/rvim corrupt: line not terminated while trying to read status. It sounds like it hates the file format (It is corrupted, crazy characters everywhere). Am I back to finding example files online? – MD-7 Dec 29 '15 at 20:25
  • “If update-alternatives complains about corrupt files again, ignore it and just proceed to delete them with the next command.” – David Foerster Dec 29 '15 at 20:30
  • 1
    PHEW! rvim was the last one. That could have been a lot worse. Sorry for skipping over that bit that you had to quote for me haha. Purged then reinstalled. Problem solved. Many thanks! – MD-7 Dec 29 '15 at 20:35
0

Similar problem on one of my servers: /var/lib/dpkg/alternatives/vtrgb corrupt

Likely from a failed install and unscheduled reboot during power outage. I fixed this by just copying the file from another server then doing:

sudo apt-get -f install 

this fixed the broken dpkg and I was able to move on with my life!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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