140

I get this error whenever I try to install programs using the terminal:

home@ubuntu:~$ apt-get install myunity
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?

Also I'm unable to install updates using the terminal.

6
  • 4
    This isn't a duplicate, same error, but different reasons. Commented Dec 1, 2012 at 18:56
  • 9
    Try sudo apt-get update Commented Feb 28, 2014 at 12:21
  • i think your gui update manager is open while you running apt-get update and one thing you must be super user or use sudo before using apt-get update Commented Feb 28, 2014 at 12:24
  • Do you even own that computer, if yes then you need to show that by being the root owner (sudo) before any installation please
    – Zuko
    Commented Mar 10, 2014 at 8:10
  • 1
    See also askubuntu.com/questions/427479/… Commented Mar 10, 2014 at 13:34

7 Answers 7

145

The solution is to read the error message: are you root?

Use sudo to run a command with root privileges, like this:

sudo apt-get update
4
  • 2
    /bin/sh: 49: sudo: not found eehm what to do here?
    – Suisse
    Commented Feb 25, 2021 at 16:04
  • @Suisse you’re not using bash which is pretty uncommon so the first question is why, secondly you might want to try simply typing /bin/bash to get into bash
    – pzkpfw
    Commented Feb 25, 2021 at 16:06
  • 5
    I am using the terminal of a docker image. from the docker dashboard. by doing /bin/bash I got into bash (different colors and highlighting) but I still get the error: E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
    – Suisse
    Commented Feb 25, 2021 at 17:27
  • @Suisse if you're using Docker it's a Docker question more than an Ubuntu question. It may depend on your container but likely you can specify that you want to be root when you enter the container, like docker exec -u root -it <container-id> /bin/bash
    – pzkpfw
    Commented Oct 2, 2021 at 8:29
31

According to the community documentation about using the terminal,

sudo: Executing Commands with Elevated Privileges

  1. Most of the following commands will need to be prefaced with the sudo command. This elevates privileges to the root-user administrative level temporarily, which is necessary when working with directories or files not owned by your user account. When using sudo you will be prompted for your password. Only users with sudo (administrative) privileges will be able to use this command. You should never use normal sudo to start graphical applications as Root (Please see RootSudo for more information on using sudo correctly.)

So, because apt-get installs software and thus affects the system, you need to use the sudo command to give yourself administrator privilages.

Thus, you command should be sudo apt-get install myunity

If you want to update your system, run

sudo apt-get update
sudo apt-get dist-upgrade

This will update your system's package database and then install any upgrades.

2
  • 15
    This does't help in getting rid of the error: unable to lock the administration directory (/var/lib/dpkg/), are you root? Commented Jul 24, 2016 at 20:59
  • This one worked for me. You shouldn't run both commands in one line as it was giving me same above error. I ran it separately and it's doing something. Let's see how it goes.
    – Raymond
    Commented Jan 19, 2023 at 15:45
13

Before running any administrative task: installing, removing, changing system wide preferences, etc. you need to be root. This is specially true for apt-get. The message itself tells you where the problem is:

are you root?

If you are not root, the install command will not work at all.

The way to fix this is using sudo before the command:

➜  ~  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?
➜  ~  sudo apt-get update
Fetched 616 kB in 25s (23.9 kB/s)

As you can notice, it completed without problems when I used sudo. If you have any open (13: Permission denied) it is almost sure that you are not root and need to use sudo.

1
  • Thanks for the help gents,as I have not set root I didn't think I'd need to use sudo but for me it's all a learning experience.Just wish you could stipulate updates in terminal
    – Frenchman
    Commented Feb 28, 2014 at 21:14
4

just run

sudo apt-get update

sudo is for running it as super user

4

Try with

sudo apt-get update 

If you still get lock error try this command It will give the process detail

ps -e | grep -e apt -e adept | grep -v grep

Then kill the process using process ID then execute the update command

And also u can delete this file your problem will solve

rm /var/lib/dpkg/lock 
4
  • 1
    Remember to close down the Software Center before using apt-get. Or else the updater gets locked. Commented Feb 28, 2014 at 12:50
  • 1
    The lock exists to protect your repository configuration files. Killing processes and removing lock files without care can lead to a badly misconfigured system. This answer is really DANGEROUS. Before removing a lock file you have to be triple sure that the process holding it has closed, or crashed, or whatever. The correct answer is @braiam 's one.
    – Rmano
    Commented Mar 10, 2014 at 14:02
  • No such file or directory: /var/lib/dpkg/lock Commented Jul 24, 2016 at 21:00
  • The updater held the lock, so I could not run apt-get install. I had to wait until the update finishes (couple of minutes only), then it worked,
    – gaborsch
    Commented Jul 11, 2017 at 13:00
2

Just read the error output: are you root? because you are not. As a regular user you don't have enough privileges to install packages.

Prepend sudo to the command to elevate the privileges. Provided that account has sudo privileges that will work.

0

I had this error and in my case I had to remove noexec on /var in /etc/fstab

which works fine on my CentOS, Fedora and Alpine Linux

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .