﻿---
title: Clean Disk Space in Ubuntu
date: 2025-06-25
excerpt: Fix apt install errors caused by no free space in /var/cache/apt/archives by locating the full partition and using a temporary cache path.
tags: [Linux, Ubuntu, OS]
thumbnail: https://assets.vluv.space/cover/Dev/Linux/clean_disk.webp
cover: https://assets.vluv.space/cover/Dev/Linux/clean_disk.webp
updated: 2026-07-08 07:44:04
lang: en
i18n:
  cn: /ubuntu_disk_clean
  translation: 2
---

## Intro

At the beginning of my internship, I applied for an Ubuntu 18 machine. Installing Neovim was inconvenient, so I installed nvim directly with `snap`.
Recently, I found that using nvim as a manpager on Ubuntu produced an error, for example:

```shell
$ man select
cannot fstatat canonical snap directory: Permission denied
/usr/bin/man: command exited with status 1: sed -e '/^[[:space:]]$/{ N; /^[[:space:]]\n[[:space:]]*$/D; }' | LESS=-ix8RmPm Manual page select(2) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB%.. (press h for help or q to quit)$PM Manual page select(2) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB%.. (press h for help or q to quit)$ MAN_PN=select(2) nvim +Man!
```

Roughly speaking, `man` did not have permission to access the snap directory. I had upgraded Ubuntu recently, so I planned to solve this by installing nvim with apt instead.
But that led to a new problem:

```shell
$ apt-get install neovim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  neovim
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 37.4 kB of archives.
After this operation, 168 kB of additional disk space will be used.
E: You don't have enough free space in /var/cache/apt/archives/.
```

I tried several online solutions. Most suggested clearing files under `/var/cache/apt/archives/` or logs under `/var/log/`, but none of them worked.

## Solution

First locate the problem. Use the `df` command to check disk usage.
It showed that the `/dev/mapper/ubuntu--vg-ubuntu--lv` partition was full, and the files under `/var/cache/apt/archives/` were stored on this partition.

```shell
$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                                16G     0   16G   0% /dev
tmpfs                              3.2G  307M  2.9G  10% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   58G   57G     0 100% /
tmpfs                               16G     0   16G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                               16G     0   16G   0% /sys/fs/cgroup
/dev/sda2                          974M  213M  694M  24% /boot
...
/dev/loop21                         13M   13M     0 100% /snap/kubectl/3512
/dev/sdb1                          492G  4.2G  462G   1% /mnt/data
tmpfs                              3.2G  8.0K  3.2G   1% /run/user/0
```

> [!caution]
>
> Judging from the path structure, `/mnt/data` is a subdirectory under `/`, but deleting files inside `/mnt/data` will not free space on the `/dev/mapper/ubuntu--vg-ubuntu--lv` partition.
>
> The reason is that `/mnt/data` and its subdirectories are actually stored on the `/dev/sdb1/` device, not on the original `/` disk space.

Once the problem was located, it was easy to handle. I freed 26 GB by running `rm -rf /root/.local/share/Trash`, then successfully installed nvim. See [Where is the .Trash folder? - Ask Ubuntu](https://askubuntu.com/a/102106/2119475) for the trash path.

### Another WorkAround

If disk space is extremely tight, you can try the following:

```shell
sudo apt -o Dir::Cache::Archives="/dev/shm/" install neovim
```

> [!NOTE]
>
> The `-o` option temporarily modifies APT configuration. Here, the cache directory is set to `/dev/shm/`, a memory-based temporary filesystem, which avoids the disk space issue.

Disabling APT's cache should also work. See [8. Disable the APT cache to save storage space](https://www.doublebastion.com/disable-the-apt-cache-to-save-storage-space/).

## Screenshot

After switching to the apt-installed nvim, nvim can be used as a manpager normally. It looks roughly like this:

![neovim man](https://assets.vluv.space/nvim_as_manpager.webp)
