在 Debian 系统中,“缓存”这个词可能指多种不同的东西。下面我按最常见场景分别说明,你可以对号入座。
Debian 使用 apt 管理软件,默认就会缓存下载的 .deb 包。
/var/cache/apt/archives/
# 清理旧缓存(保留已下载但未安装的)
sudo apt clean
# 删除已安装软件的旧版本缓存
sudo apt autoclean
编辑:
sudo nano /etc/apt/apt.conf.d/95cache
示例:
Dir::Cache::archives "/var/cache/apt/archives";
APT::Cache-Limit "100000000"; # 100MB
适合多台 Debian 机器共享缓存。
sudo apt install apt-cacher-ng
客户端配置:
sudo nano /etc/apt/apt.conf.d/01proxy
Acquire::http::Proxy "http://192.168.1.10:3142";
Debian 默认使用 Linux 的 page cache,无需配置。
查看:
free -h
手动释放(一般不需要):
sudo sync
sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
Debian 默认没有 DNS 缓存。
sudo apt install dnsmasq
sudo systemctl enable --now dnsmasq
配置 DNS:
/etc/resolv.conf
nameserver 127.0.0.1
location ~* \.(jpg|css|js)$ {
expires 7d;
}
pip config set global.cache-dir ~/.cache/pip
npm config set cache ~/.npm
可以告诉我:
我可以直接给你完整配置文件 + 命令。