0

I have a similar problem as this

When doing apt-get update I got

apt-get update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

apt-get upgrade
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?

However in that question everybody answered "use sudo" which yes, it permits the execution but it is not an answer because:

  • Previously in my PC I could do update and upgrade without sudo. So I would like to know how to be able to do update and upgrade without sudo again

edit: The solution is not using sudo all the time. For reference check this article or this article which actually try to solve the problem (unfortunately their solution didnt work for me but it goes in the direction of the problem)

Edit2. One other reason why sudo *should not be * necessary is the following: I use a lot of docker images. When you build a docker image you use a Dockerfile. In the docker file you have things like

RUN apt-get update && apt-get remove -y x264 libx264-dev
RUN apt-get update && apt-get upgrade -y && apt-get install -y sudo clang-format wget apt-utils

if sudo were necessary, then we could not build docker images at all. So far I have build several of these because sudo was not necessary.

KansaiRobot
  • 417
  • 7
  • 18
  • 1
    Does this answer your question? [Permission denied, are you root?](https://askubuntu.com/questions/223484/permission-denied-are-you-root) – vanadium May 21 '21 at 11:32
  • The answer is in the output of your command. – vanadium May 21 '21 at 11:32
  • @vanadium As **Explicitly stated** in the question, that question **Does not** answer the question. – KansaiRobot May 21 '21 at 11:51
  • Does this answer your question? [E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)](https://askubuntu.com/questions/1109982/e-could-not-get-lock-var-lib-dpkg-lock-frontend-open-11-resource-temporari) – karel May 21 '21 at 12:00
  • 2
    "Previously in my PC I could do update and upgrade without sudo". That was not a default system. For system operations on Ubuntu, you need `sudo`. – vanadium May 21 '21 at 12:12
  • Maybe you just used `sudo -i` or equivalent to make yourself equivalent to root, meaning you didn't need to use `sudo`... however that's generally unwise, and why `sudo` is the preferred & safer option. – guiverc May 21 '21 at 12:20
  • Please see additional Edit2 – KansaiRobot May 21 '21 at 12:41
  • 1
    The fact remains that on a default ubuntu install, you will not update and upgrade as a normal user. This is not Windows 95. – vanadium May 21 '21 at 12:46
  • How do you build docker images in that case? – KansaiRobot May 21 '21 at 12:47
  • 1
    You are confusing the user of your actual OS and the user in the docker image. – terdon May 21 '21 at 12:52
  • "sudo *should not be* necessary"... that is a very strong statement, and I personally disagree. I don't mean to put together a poll among users/admins, but I guess its outcome... – sancho.s ReinstateMonicaCellio May 21 '21 at 15:21
  • @sancho.sReinstateMonicaCellio I agree, you have made me think. Still, there is something seriously wrong with my PC so I am investigating what is wrong and writing another question later on.. Thanks – KansaiRobot May 21 '21 at 15:25
  • As you said, that possibly pertains to a different question. Some diagnostic commands might be needed. – sancho.s ReinstateMonicaCellio May 21 '21 at 15:26

1 Answers1

2

The default for apt-get update is requiring sudo. If your system did not require it at a given point (and that is typically not a good idea), that is because someone did something.

If you want to recover that behaviour, thinking that it should be the default and somehow it changed, I suggest you reconsider the idea, and stick with sudo apt-get update.

If you are aware of the risks involved, and you still want apt-get update without sudo, you can open a terminal and type sudo visudo. At the end of the file (really the last line in it) type %yourusername% ALL=NOPASSWD: /usr/bin/apt-get install where %yourusername% is replaced by your username (source). That still requires sudo but it does not prompt for a password.

terdon
  • 98,183
  • 15
  • 197
  • 293
  • If that is the case how can anybody build docker images that has RUN apt-get update. NOT RUN sudo ... – KansaiRobot May 21 '21 at 12:46
  • I removed the suggestion of messing with the permissions of system directories. That will very likely lead to problems and is a very, very bad idea. – terdon May 21 '21 at 12:50
  • @KansaiRobot presumably, they build the images as root. More likely, the user _inside the docker image_ is root. The commands you give are supposed to be run within the docker image, and if they ran without `sudo`, then the docker image was configured to run as the root user (within the OS of the image). – terdon May 21 '21 at 12:51
  • @terdon - It is ok if you remove a "dangerous" comment. Alternatively, you could have added a **strong** warning, and let the user decide. Personally, I guess the latter option is less intrusive with the answer. And the resulting answer would have been in line with many others I see in SE and other forums. – sancho.s ReinstateMonicaCellio May 21 '21 at 15:18
  • Feel very free to revert, it's your answer! That's why I made sure to leave a comment so you would see it. You really, really don't want to change the permissions of system dirs. And the fact that you were suggesting it without actually knowing if it would break anything else made it even worse :( However, if you think that is good advice, you are of course free to bring it back. I admit I will then probably change my upvote to a downvote (I cannot upvote an answer suggesting that solution), but it's your call. – terdon May 21 '21 at 16:32
  • @terdon - That's fine, it was a minor comment. Thanks! – sancho.s ReinstateMonicaCellio May 21 '21 at 16:43