How to fix "Could not open lock file" because "Permission denied"? [duplicate]

Whenever trying to install any software and update manger,

I get an error stating

Package operation failed
The installation or removal of a software package failed

When I run sudo apt-get update I got this result:

conan51xd@conan51xd-Lenovo-B470:~$ sudo apt-get -f install
[sudo] password for conan51xd: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
conan51xd@conan51xd-Lenovo-B470:~$ apt-get update
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

Solution 1:

E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

This line says you are not authorized to install/update. You need to be root to do it....

You can add sudo before apt-get or you can do sudo -s to be root.

Example: sudo apt-get update

or

sudo -s will consider you as root until you close your terminal.

Then

apt-get update

Solution 2:

I had the same error, this worked for me:

This error indicates that you (or some program/script) changed the permissions of the file /var/lib/dpkg/status. Please change them back via: "sudo chmod 644 /var/lib/dpkg/status" in order to fix the issue.

I ended up opening terminal:

sudo nautilus

navigating to the folders/files, and changing permissions to

ME - FOLDER:FULL ACCESS / FILES: READ WRITE

ROOT - FOLDER: FULL ACCESS / FILES: READ ONLY

The problem came when my permissions got screwed when trying to fix a kernel issue I had with an Nvidia driver... but that's another story..

I hope this helps...

Solution 3:

  1. sudo -s (gives the root access)
  2. apt-get update (get the updates)
  3. apt-get upgrade (upgrades the system)

apt-get update && apt-get upgrade doesn't work on every system so run the commands separately.