温馨提示×

debian nodejs缓存怎么清

小樊
40
2026-10-25 20:55:42
栏目: 编程语言

在 Debian 上清理 Node.js 相关缓存,通常看你指的是哪一类缓存。下面按常见场景说明:


1. 清理 npm 缓存(最常见)

如果你是用 npm 安装的包:

npm cache clean --force

查看缓存目录位置:

npm config get cache

一般路径是:

~/.npm

也可以手动删除:

rm -rf ~/.npm/_cacache

2. 清理 yarn 缓存

如果你用的是 yarn:

yarn cache clean

缓存目录:

yarn cache dir

3. 清理 pnpm 缓存

如果你用的是 pnpm:

pnpm store prune

或查看缓存路径:

pnpm store path

4. 清理 Node.js 模块缓存(node_modules)

项目本地的依赖缓存:

rm -rf node_modules
npm install

或(yarn):

rm -rf node_modules yarn.lock
yarn install

5. 清理系统级 Node.js 包缓存(apt)

如果你是通过 Debian 的 apt 安装的 Node.js:

sudo apt clean

或只清 Node 相关:

sudo apt-get clean nodejs

查看已安装版本:

node -v
npm -v

6. 如果是“运行时的内存缓存”

Node.js 本身没有全局缓存机制,如果你指的是:

  • 应用内缓存(如 require 缓存)
  • Redis / Memcached
  • 自己写的缓存逻辑

那就需要:

delete require.cache[require.resolve('./module')]

或重启 Node 服务:

systemctl restart yourapp

如果你能补充说明:

  • 用的是 npm / yarn / pnpm?
  • 是系统缓存、依赖缓存还是运行时缓存?

我可以给你更精确的命令。

0 踩