You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was exploring setting up a machine that would continuously test against different versions of node. Seeing how nvm is very easy to use for installing (think nightly nvm i 6 etc) my next concern was removing older versions of node. A nvm prune suggestively should remove all older versions of each major; for instance:
@ljharb said:
So the idea is that nvm prune would uninstall all but the latest node, nvm prune X would prune everything under that X that wasn't the latest, etc?
Yes. Similar to how other package managers provide cleanup functions. The difference here is that nvm obviously should allow 6.3.0 and 6.3.1 installed simultaneously whereas other package managers might choose to replace versions.
@ljharb said:
What happens if you're on 6.3.0, and you run nvm prune or nvm prune 6?
Nothing. nvm prune should be considered safe, meaning it will only remove versions from 'majors' that has more than one version installed. Also, if one version is set as default, this should also be seen as sticky.
Sounds about right. Regarding error-handling I think we should follow the current decision-making. Do you always exit on first error? I think that would be a good idea.
With nvm uninstall, it checks permissions first, and only proceeds if it thinks it'll be able to completely remove everything. Since this is a "batch" argument, there's no precedent for how to handle an error in one job.
I am concerned that this feature could be unnecessarily destructive, especially if the default is "everything" - i'd certainly prefer nvm prune to require a numeric version filter.
Running the script:
Run it as . ~/prune_nvm.sh, so you use your current env
After it:
With this script, I preserve different major versions but delete old minor or patch ones.
I also use a script that automatically installs (or sets) the node version specified in .nvmrc as soon as I access its folder:
loadnvmrc() {
local node_version="$(nvm version)"local nvmrc_path="$(nvm_find_nvmrc )"if [ -n"$nvmrc_path" ];thenlocal nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")if [ "$nvmrc_node_version"="N/A" ];then
nvm install
elif [ "$nvmrc_node_version"!="$node_version" ];then
nvm use
fielif [ "$node_version"!="$(nvm version default)" ];thenecho"Reverting to nvm default version"
nvm use default
fi
}
loadnvmrc
cd() {
builtincd"$1"
loadnvmrc
}
Hello everyone, this weekend I was working and I was wondering if here was a feature to remove old versions installed in my local, so I worked on this feature on my PR
Including only the latests versions, and adding a dry-run flag to avoid possible problems removing unwanted versions.
Still very relevant, without a nvm prune command, old Node versions accumulate silently. On a long-running Mac dev machine or CI runner, I've seen ~/.nvm grow to 5-10GB+.
Quick audit:
du -sh ~/.nvm/ 2>/dev/null
du -sh ~/.nvm/versions/node/*/ 2>/dev/null | sort -hr
Manual workaround to remove all but the latest patch of each major:
# List installed versions
nvm ls
# Uninstall specific versions
nvm uninstall 18.17.0
nvm uninstall 16.20.0
# Also clean npm/yarn caches that come with each version
npm cache clean --force
On macOS, nvm is just one of many tools that accumulate disk usage. Add Volta, pyenv, SDKMAN, Homebrew, Xcode DerivedData, Docker, Gradle, Cargo, and pip caches, and you can easily hit 50-100GB+ of recoverable space. ClearDisk is a free, open-source menu bar utility that monitors 44+ developer cache paths — including ~/.nvm — so you can see at a glance what's eating your disk.
Activity
ljharb commentedon Aug 10, 2016
So the idea is that
nvm prunewould uninstall all but the latestnode,nvm prune Xwould prune everything under that X that wasn't the latest, etc?What happens if you're on 6.3.0, and you run
nvm pruneornvm prune 6?jbergstroem commentedon Aug 10, 2016
Yes. Similar to how other package managers provide cleanup functions. The difference here is that
nvmobviously should allow 6.3.0 and 6.3.1 installed simultaneously whereas other package managers might choose to replace versions.Nothing.
nvm pruneshould be considered safe, meaning it will only remove versions from 'majors' that has more than one version installed. Also, if one version is set asdefault, this should also be seen as sticky.ljharb commentedon Aug 10, 2016
I mean if you have 6.3.0 and 6.3.1 and 6.2.9 installed, and you're on 6.3.0, and you run
nvm pruneljharb commentedon Aug 10, 2016
What about
.nvmrcversions, which are PWD-sensitive? Shouldn't those be sticky too?jbergstroem commentedon Aug 10, 2016
I suggest
prunecalling uninstall, meaning whatever barriers being in place there should be applied as well.ljharb commentedon Aug 10, 2016
OK, so:
nvm prune:nvm_ls), filter outnvm currentandnvm version node("whatever the latest is in that list")nvm uninstallon each onenvm prune X:nvm_ls X), filter outnvm currentand "whatever the latest is in that list"nvm uninstallon each onejbergstroem commentedon Aug 10, 2016
Sounds about right. Regarding error-handling I think we should follow the current decision-making. Do you always exit on first error? I think that would be a good idea.
ljharb commentedon Aug 10, 2016
With
nvm uninstall, it checks permissions first, and only proceeds if it thinks it'll be able to completely remove everything. Since this is a "batch" argument, there's no precedent for how to handle an error in one job.jbergstroem commentedon Aug 10, 2016
I still think that bailing early is the best path here but I don't have a strong opinion; happy to do whatever consensus would be.
ljharb commentedon Aug 10, 2016
I am concerned that this feature could be unnecessarily destructive, especially if the default is "everything" - i'd certainly prefer
nvm pruneto require a numeric version filter.jbergstroem commentedon Aug 10, 2016
I'd be ok with that. Majors would likely be known in a test environment.
bjfisher-cbg commentedon May 20, 2020
relnetops commentedon Feb 5, 2021
Ping. What's the status of this request?
ljharb commentedon Feb 5, 2021
@relnetops There's been no PR, and I'm still concerned about the destructiveness.
Farenheith commentedon Jan 14, 2023
I locally use a simple script to get rid of old node versions from nvm:
Take a look:
Before

Running the script:

Run it as
. ~/prune_nvm.sh, so you use your current envAfter it:

With this script, I preserve different major versions but delete old minor or patch ones.
I also use a script that automatically installs (or sets) the node version specified in .nvmrc as soon as I access its folder:
esguerrag commentedon Feb 23, 2026
Hello everyone, this weekend I was working and I was wondering if here was a feature to remove old versions installed in my local, so I worked on this feature on my PR
Including only the latests versions, and adding a
dry-runflag to avoid possible problems removing unwanted versions.Hope this could be helpful.
bysiber commentedon Mar 5, 2026
Still very relevant, without a
nvm prunecommand, old Node versions accumulate silently. On a long-running Mac dev machine or CI runner, I've seen~/.nvmgrow to 5-10GB+.Quick audit:
Manual workaround to remove all but the latest patch of each major:
On macOS, nvm is just one of many tools that accumulate disk usage. Add Volta, pyenv, SDKMAN, Homebrew, Xcode DerivedData, Docker, Gradle, Cargo, and pip caches, and you can easily hit 50-100GB+ of recoverable space. ClearDisk is a free, open-source menu bar utility that monitors 44+ developer cache paths — including
~/.nvm— so you can see at a glance what's eating your disk.