Ubuntu – Unable to lock the administration directory (/var/lib/dpkg/) error when trying to install unrar from the terminal in Ubuntu

rootUbuntu

I am getting this error when trying to install unrar unarchiver for .rar files from the terminal in Ubuntu.

E: Could not open lock file /var/lib/dpkg/lock - open (2: No such file or directory)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

Best Answer

  • Run the following command :

    sudo rm /var/lib/dpkg/lock
    

    Create missing folders (use the command ls -l /var/lib/dpkg/ first to display the existing folders, if somes floders exist do not re-create it agin):

    sudo mkdir -p /var/lib/dpkg/{alternatives,info,parts,triggers,updates,methods,available,diversions}
    

    Move dpkg.status.0 and repair the base file:

    sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
    sudo apt-get download dpkg
    sudo dpkg -i dpkg*.deb
    sudo apt-get download base-files
    sudo dpkg -i base-files*.deb
    sudo apt update && sudo apt upgrade
    

    Check and repair broken dependencies:

    sudo apt-get check
    sudo apt -f install
    
  • Related Question