Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~/.nvm directory taking up 12gb after fresh install? #2418

Open
thomasfw opened this issue Jan 25, 2021 · 18 comments
Open

~/.nvm directory taking up 12gb after fresh install? #2418

thomasfw opened this issue Jan 25, 2021 · 18 comments
Labels
installing node Issues with installing node/io.js versions. needs followup We need some info or action from whoever filed this issue/PR. OS: Mac OS

Comments

@thomasfw
Copy link

Operating system and version:

  • Mac (M1) - Big Sur 11.1

How did you install nvm?

  • Install script in readme.

What steps did you perform?

  • Installed nvm.
  • Ran nvm install v15

What happened?

The ~/.nvm/ directory is taking up ~12gb.

After running nvm cache clear (#1457) the directory size is 92mb.

Is this normal?

@ljharb
Copy link
Member

ljharb commented Jan 25, 2021

I would not expect the cache files to be that large, certainly - but nvm has no control over what artifacts the compile produces.

Note that on an M1 Mac, you might be compiling a Rosetta version, which may have something to do with it. What does node -p process.arch print out?

@ljharb ljharb added installing node Issues with installing node/io.js versions. OS: Mac OS labels Jan 25, 2021
@zulaica
Copy link
Contributor

zulaica commented Feb 13, 2021

What does node -per process.arch` print out?

There appears to be a typo. The command should be node -p process.arch.

As for the directory taking up so much disk space after building from source, I had a similar outcome. As noted, running nvm cache clear freed up disk space. This seems to be normal/expected.

@ljharb ljharb added the needs followup We need some info or action from whoever filed this issue/PR. label Feb 13, 2021
@thomasfw
Copy link
Author

node -p process.arch confirms this is compiling the arm64 version.

If this is expected behaviour would it be beneficial to add a note to the readme recommending use of nvm cache clear after an installation, or better yet have the nvm install command clear the cache automatically after building from source?

@ljharb
Copy link
Member

ljharb commented Mar 25, 2021

@thomasfw I don't think that should be a recommendation. What's the point of the cache if it's cleared right after populating it?

@thomasfw
Copy link
Author

@ljharb If those cached files didn't total > 12gb from a single install I'd probably agree. But in this case, I can't see how preserving such an enormous cache has any added benefit to me, and personally i'd take the significantly lower footprint over any speed increase the cache provides when installing different node versions (assuming that's its purpose).

@ljharb
Copy link
Member

ljharb commented Mar 25, 2021

That is indeed its purpose, and since disk space is effectively infinite and free, while CPU time is quite expensive and limited, I think this is the appropriate default. You are more than welcome to nvm cache clear after your install commands if you have different priorities.

@zulaica
Copy link
Contributor

zulaica commented Mar 25, 2021

Additionally, compiling from source is not required. The README contains instructions on how to install Node for the correct architecture x86 without needing to compile for arm. You'll need to scroll to the bottom of the linked section for the header "Macs with M1 chip".

Edit: I originally misspoke. I should have had my coffee first. The x64 binaries run under Rosetta if installed this way and run much faster than the local builds that are compiled from source.

@zulaica
Copy link
Contributor

zulaica commented Mar 25, 2021

For what it's worth, this is strictly when attempting to install older versions of Node. Node 15 is available as a pre-built binary for arm builds from source properly and will install the correct version run quickly/efficiently without needing to resort to the workaround.

Edit: I really need to drink my coffee already. 😅

@zulaica
Copy link
Contributor

zulaica commented Mar 25, 2021

NodeJS don't plan on releasing M1-compatible binaries for v15 (and below). They have an issue in their repo that is tracking progress for v16 (which will include M1-compatible binaries). What I hadn't noticed before is that compiling v15 from source for M1 is not officially supported by Node which leaves running the x64 binaries through Rosetta as the current best solution.

Perhaps instead of opting to compile from source, nvm could instead download the darwin-x64 binary after the darwin-arm64 binary download fails? If this seems like a good idea, I could try submitting a pull request.

@ljharb
Copy link
Member

ljharb commented Mar 25, 2021

@zulaica if node commits to never actually providing a prebuilt arm64 binary, then we could hardcode that assumption into nvm, and not even bother attempting the arm64 one for node versions where it's never an option.

@JakobJingleheimer
Copy link

JakobJingleheimer commented Apr 4, 2021

I encountered this recently, and running nvm cache clear freed up over 35 GB of disk space.

That…does not sound like cache. I've compiled maybe 3 (possibly 4) minor versions of node on this laptop, and it would seem each installation generates roughly 10 GB of cache. That seems highly suspicious, like it's not actually re-using anything—unless the cache is intended for re-compiles of the exact same version?? If so, that seems like a very unlikely use-case (aside from CI) and hugely wasteful.

@ljharb
Copy link
Member

ljharb commented Apr 4, 2021

The cache is solely intended for that purpose (it’s not possible to cache anything else), and the reason is mostly because disk space is effectively infinite and free, while processing time is finite and expensive. Reinstalling node happens far more often in my experience than my disk gets filled.

I’d be willing to accept a PR that adds an env var that can disable automatic caching of source builds, specifically, if remembering to nvm cache clear is burdensome.

@JakobJingleheimer
Copy link

Disk space is not infinite, but SSD is simple to reclaim, so not a huge problem.

Having to run cache clear isn't burdensome at all—but having to know it exists is (the old adage "you don't know what you don't know").

It might be only me and the few dozen devs I've regularly observed using nvm, but I would bet almost no-one frequently re-builds the exact same version of node on the same machine multiple times.

If true, would you accept a PR that introduces an ENV var to enable caching (where it's disabled by default)?

For me, this useless cache represented 23% of my total disk space usage. That's not exactly trivial.

@ljharb
Copy link
Member

ljharb commented Apr 4, 2021

That would be a breaking change, so I’m not inclined to change the default.

@lisovyk
Copy link

lisovyk commented Aug 22, 2022

Would be nice to have it be mentioned somewhere on installation. Stumbled upon this thread because of huge .nvm folder :)
After reading the thread - something like "Yes (recommended) | No" option on install seems somewhat convenient to me.

@ljharb
Copy link
Member

ljharb commented Aug 22, 2022

@lisovyk where would that show up? nvm's installation must be headless and promptless, or it will break use cases.

#2418 (comment)

I’d be willing to accept a PR that adds an env var that can disable automatic caching of source builds, specifically, if remembering to nvm cache clear is burdensome.

@cdilga
Copy link

cdilga commented Sep 15, 2022

I’d be willing to accept a PR that adds an env var that can disable automatic caching of source builds, specifically, if remembering to nvm cache clear is burdensome.

Has this been done?
If not I'll make a PR, mine was 55 GB on a 256 GB mac M1 and just started failing to install new versions because there wasn't enough space.

@ljharb
Copy link
Member

ljharb commented Sep 15, 2022

@cdilga nope, it's not been done; a PR would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installing node Issues with installing node/io.js versions. needs followup We need some info or action from whoever filed this issue/PR. OS: Mac OS
Projects
None yet
Development

No branches or pull requests

7 participants
@ljharb @JakobJingleheimer @cdilga @zulaica @thomasfw @lisovyk and others