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
1please anyone help by solving my error. – hasee – 2016-08-01T05:32:25.240
As the error asks, are you root or running the command with
sudo
? – Julie Pelletier – 2016-08-01T05:33:17.160sudo apt-get install whatever
should do the trick. Missing sudo as pointed out by @JuliePelletier – pun – 2016-08-01T05:34:36.447I am trying to install $ sudo apt-get install unrar.but still it showing the same error – hasee – 2016-08-01T05:36:32.367
Is this happening on a fresh install? – Julie Pelletier – 2016-08-01T05:39:42.083
rm -r /var/lib/dpkg/* long back i run this command in my terminal.after running this command i am getting bellow error every time when i am trying to install any software sudo apt-get install unrar [sudo] password for user: 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? – hasee – 2016-08-01T05:42:40.537
1Do you get any result when running
sudo ls -l /var/lib/dpkg
? – Julie Pelletier – 2016-08-01T05:45:40.083ls: cannot access '/var/lib/dpkg': No such file or directory this is the result i am getting after entering the sudo ls -l /var/lib/dpkg – hasee – 2016-08-01T05:48:11.727
1Then try
sudo mkdir /var/lib/dpkg
but I suspect the problem could be much worse. – Julie Pelletier – 2016-08-01T05:53:45.400user@user-Vostro-3800:~$ sudo mkdir /var/lib/dpkg user@user-Vostro-3800:~$ sudo -i root@user-Vostro-3800:~# sudo mkdir /var/lib/dpkg mkdir: cannot create directory ‘/var/lib/dpkg’: File exists – hasee – 2016-08-01T05:57:21.433
1@hasee, obviously, you're getting the error messages because something is messed up and not working normally. Your question doesn't contain any history of how you got to this point or diagnostic details. Some of that is in comments, but it's incomplete and hard to follow. People will be better able to help if you edit the question and add the detail from the comments (and do it in an organized way). – fixer1234 – 2016-08-01T06:26:47.917
@karel, looks like you have some insight that I don't. You think all of the details in the comments are basically noise (not really relevant to a solution), and the 2nd and 3rd bullets in your answer pretty much have to cover the problem? – fixer1234 – 2016-08-01T07:13:25.107
@hasee, I had shut down for the night and now can't tell from the comment timings whether karel's super-cure worked (if it did, you can accept the answer by clicking the checkmark; that will let people know the problem is solved and identify that as a proven solution for others with a similar problem). If it didn't solve it, my understanding is that things can get hosed in a way apt can't fix. I think that's where Julie Pelletier was going with the comment about a fresh install. Sometimes the most reliable, and fastest, solution is to restore from a backup or do a clean install. (cont'd) – fixer1234 – 2016-08-01T16:56:25.543
See if your system has the Aptik Migration Utility. That will create a list of all the changes you've made to the stock installation and provide a mechanism to do an automated recreation of the current configuration. – fixer1234 – 2016-08-01T16:56:33.513
1@hasee: Please double-check what you tried because
sudo ls -l /var/lib/dpkg
can not tell you that there is no such file or directory whilesudo mkdir /var/lib/dpkg
would tell you that it exists. – Julie Pelletier – 2016-08-01T16:56:51.717Related thread on askUbuntu exchange - Permission denied, are you root?
– RBT – 2018-05-10T00:06:18.800