38

When I executed sudo apt update I'm getting

Reading package lists... Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (20: Not a directory)

Also, I was getting a status error which I solved using

sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status

I tried sudo mkdir /var/lib/apt/lists/partial as suggested in few other threads

mkdir: cannot create directory ‘/var/lib/apt/lists/partial’: Not a directory

Even I tried sudo mkdir /var/lib/apt/lists/

Any other solution?

stefun
  • 1,261
  • 3
  • 24
  • 54
  • 1
    Prior to this same issue arising in my docker file, there was an earlier error in the logs to say => ERROR [3/3] RUN apt-get update. Who would imagine that this would be related to the user permissions! Upon careful inspected noted this error and that's how I landed in this post and the below answer from @ssi-anik helped resolve the issue. Adding this comment so Google may search this page as the first result for both these issues! ;) Thanks all. – SydMK Aug 19 '22 at 10:07
  • I had this after trying to clean apt after a bad install. This helped: https://askubuntu.com/a/358971/1718249 – theSparky Aug 01 '23 at 15:31

8 Answers8

109

The answer may be inappropriate here. But as I came here others may land here too.

If you're using docker and you face the same issue you can do like the following.

USER root
# RUN commands
USER 1001

Reference: Link

ssi-anik
  • 2,998
  • 3
  • 23
  • 52
  • 5
    Alternatively, if you're running after-the-fact (e.g. to check if a container needs an update), try `sudo docker run -it --rm --user 0 ....` – starbeamrainbowlabs Aug 13 '20 at 21:03
  • 4
    At the risk of pointing out the obvious: "USER 1001" assumes that that's the user you want your container (or subsequent dockerfile entry) to run as. If you started with `FROM foo` then you'd want to put whatever user FOO configured in that place. – MatrixManAtYrService Jun 16 '21 at 13:30
  • 1
    This answer is still valid in 2021 - fixed my issue just now. Thanks. –  Jul 02 '21 at 13:12
22

You can try adding -u 0 in the command

sudo docker exec -u 0 -it ContainerID bin/bash

According to Docker, the u flag defines what username or UID in the system for the container to run as, setting -u 0 means you run the container as root, use it with caution! Reference here

v.ng
  • 533
  • 5
  • 10
2

The same happened to me. I follow as guide this answer:The package lists or status file could not be parsed or opened

I assumed my lists were corrupted. I went to /var/lib/apt/ I saw a file (lists@) instead of a directory. I deleted it (sudo rm lists) and re-created the path (sudo mkdir -p /var/lib/apt/lists/partial). Double-check the path gets created.

Jofe
  • 2,489
  • 1
  • 12
  • 12
2

I ran into the same issue while trying to build a new container and experimenting with Dockerfile for a while. What saved me finally was just to delete all containers I've created during this process using docker rm.

Ngoral
  • 4,215
  • 2
  • 20
  • 37
2

this is how it works access as root in docker bash and install your apps

get id container by name

sudo docker ps -aqf "name=name=es01"

access bash as root

sudo docker exec -u 0 -it 3d42134dfd59 bash

Example install:

apt get update
apt-get install nano
Alex Hurtado
  • 349
  • 2
  • 7
1

I had a similar error when using bitnami spark image and docker exec command with arguments -u didn't work for me. I found my answer in the image documentation here.

In case you are using a docker image, it might be that the image is a non root container image. Read the documents of the docker image provider to find the solution to see how you can use the image as a root container image.

Gru97
  • 471
  • 5
  • 8
  • The same works with apache/spark-py image as well. Just specify `user:root` after image in docker compose file. – Dhruv May 29 '23 at 11:56
0

I had this same issue when trying to install an Typora on Ubuntu 20.04.

I was running into the error whenever I run the command below:

# add Typora's repository

sudo add-apt-repository 'deb https://typora.io/linux ./'

Here's how I solved it:

I disconnected and reconnected my network connection, and when I ran the command again, it worked fine.

I think it was an issue with my network connectivity.

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
-1

You first need to have super user privilege by typing in sudo -i and then inserting your password.

PiRocks
  • 1,708
  • 2
  • 18
  • 29