Most of the time apt install just works. When it does not, it is usually one of three messages: another program holds the lock, the package cannot be found, or an earlier installation was interrupted. This guide shows what each message means and what to do.
The examples use Ubuntu 26.04 LTS. Run the commands as root, or put sudo in front of them. How apt works in general: Install, Update and Remove Programs on Ubuntu and Debian With apt.
1. Could Not Get Lock
apt waits and repeats this line:
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (apt-get)...
apt-get does not wait and stops with:
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (apt-get) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
Only one program may install software at a time. The name in brackets is the one that is working right now: another apt or apt-get, perhaps in a second SSH session, or unattended-upgr, the automatic security updates. These run once a day and shortly after a start of the server, which is why the message often appears on a server you have just received or restarted.
See how long that program has been running; use the number from the message:
ps -p 1234 -o pid,etime,cmd
- Wait. In most cases the other program is finished after a few minutes, and
aptcontinues by itself. - Do not delete the lock files, even if a page on the Internet says so. Two installations at the same time can damage the list of installed packages.
- If the other program has made no progress for a long time, end it with
kill 1234, without-9, and then repair as shown in step 3.
More about the automatic updates: Automatic Security Updates on Ubuntu and Debian.
2. Unable to Locate Package
Error: Unable to locate package notapackage123
apt does not know a package with this name. Refresh its list first, because on a new server the list can be old:
apt update
Then check the exact name. This searches the names of all packages:
apt search --names-only '^htop$'
htop/resolute,now 3.4.1-5build2 amd64 [installed] interactive processes viewer
Leave out ^ and $ to find every package whose name contains the word. Names are written in lowercase letters.
3. dpkg Was Interrupted
When an installation was cut off, for example because the SSH session closed or the server restarted, the next apt command refuses to work and says that dpkg was interrupted and that you must run dpkg --configure -a. Do exactly that, and then let apt repair what is missing:
dpkg --configure -a apt -f install
Check afterwards that nothing is left half installed. This command prints nothing when all is well:
dpkg --audit
Start a large upgrade in tmux, so that it continues when your connection drops: Keep a Program Running on Linux.
4. Other Messages
| Message | What to do |
|---|---|
No space left on device | The disk is full. Free space first: What Fills the Disk and What Loads the Server. |
Temporary failure resolving | The server cannot reach the Internet or its name servers: Check the Network of Your Linux Server: ping, mtr and iperf3. |
are you root? | Put sudo in front of the command, or log in as root. |
Good to Know
- What apt did before:
tail -n 20 /var/log/apt/history.logshows the last installations and removals with their date and the command. Add these lines when you ask support for help. - Is a restart waiting after updates? See Automatic Security Updates on Ubuntu and Debian.