What Is the .node-gyp Folder and Is It Safe to Delete?

Yes, it's safe to deleteDiskmack safety tier: Safe to clean
~/Library/Caches/node-gyp~/.node-gyp

Yes, you can delete the .node-gyp folder. It's a cache of Node.js header files that node-gyp downloads when it compiles native addons, and it re-downloads whatever it needs the next time a native module builds. Nothing you created lives in there. The same goes for its sibling at ~/Library/Caches/node-gyp.

What it is

node-gyp is the build tool npm reaches for when a package contains native code, meaning C or C++ that has to be compiled on your machine instead of just copied into node_modules. Packages like sqlite3, canvas, and bcrypt go through it whenever there's no prebuilt binary for your exact Mac and Node combination. To compile against your exact Node.js version, node-gyp needs that version's header files, so it downloads them from nodejs.org once and keeps them around for the next build.

Depending on which version of node-gyp did the downloading, that cache lands in one of two places: ~/.node-gyp (the older location, hidden in your home folder) or ~/Library/Caches/node-gyp (the current location on macOS). Plenty of Macs have both. Inside you'll find one folder per Node version you've ever compiled against, so if you've upgraded Node a few times or hop between versions with nvm, the copies pile up. Each set of headers is modest on its own, typically tens of megabytes, but a machine that has churned through many Node versions can quietly accumulate several hundred megabytes of headers it will never read again.

Is it safe to delete?

Delete either folder, or both, whenever you like. They contain nothing but downloaded copies of files that live permanently on nodejs.org. The next time npm installs a package with native code, node-gyp notices the headers are missing, downloads them again, and carries on. You won't break Node, npm, or any project you've already installed.

The only cost is that first rebuild: one extra download of the headers for your current Node version, which needs a network connection. If you often compile native modules offline, keep it. Everyone else can take the space back without a second thought. Diskmack identifies this folder automatically and cleans it the safe way.

How to check its size

In Finder: In Finder, choose Go > Go to Folder (Cmd-Shift-G), paste ~/Library/Caches and press Return. Select the node-gyp folder and press Cmd-I to see its size. For the older location, open your home folder (Cmd-Shift-H), press Cmd-Shift-. (period) to reveal hidden files, then select .node-gyp and press Cmd-I.

In Terminal:

du -sh ~/Library/Caches/node-gyp ~/.node-gyp

The ~ expands to your home folder; if one of the two paths doesn't exist, du says so and still reports the other.

How to clean it

  1. Make sure no npm, yarn, or pnpm install is currently running, so nothing is mid-compile.
  2. In Finder, choose Go > Go to Folder (Cmd-Shift-G) and enter ~/Library/Caches.
  3. Select the node-gyp folder and move it to the Trash (drag it there, or press Cmd-Delete).
  4. Open your home folder (Cmd-Shift-H) and press Cmd-Shift-. (period) to reveal hidden files. If you see a .node-gyp folder, move it to the Trash too, then press Cmd-Shift-. again to hide the rest.
  5. Empty the Trash to actually reclaim the space.

The first native module build after cleaning re-downloads headers for your current Node version, so expect that one install to run a little longer.

Will it come back?

It comes back exactly when a native addon compiles again, and only then. Pure JavaScript packages never touch it. When it does return, it holds headers for just the Node version you're running at that moment, so it usually comes back far smaller than what you deleted. The bloated version of this folder, stuffed with headers for half a dozen retired Node versions, only rebuilds if you compile against half a dozen Node versions again.

Common questions

Why do I have both ~/.node-gyp and ~/Library/Caches/node-gyp?

Older releases of node-gyp cached headers in ~/.node-gyp. Newer releases use the standard macOS cache location at ~/Library/Caches/node-gyp. A Mac that has been through a few Node upgrades often has both. They're the same kind of cache, and both are safe to remove.

Will deleting it break npm install?

No. Installs of pure JavaScript packages never touch this cache. The next install that compiles native code downloads fresh headers automatically. The only difference you'll notice is one extra download during that install.

Do I need to reinstall node-gyp after deleting the folder?

No. node-gyp is a program that ships bundled with npm; this folder is just its download cache. Deleting the cache doesn't touch the tool itself.

What are the version-numbered folders inside it?

One per Node.js version you've compiled native modules against. If you see folders named 16.20.0, 18.19.1, and 20.11.0, those are header sets for three different Node versions. Any that don't match a version you still run are dead weight.

Related folders