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.

1 Answers1

3

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
  • 100,812
  • 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