Algorithms, Blockchain and Cloud

How to Clean Up NVM Node Versions Except One?


nodejs How to Clean Up NVM Node Versions Except One?

Node.JS

How to Remove All NVM Node.js Versions Except One

NVM is Node Version Manager, which can be installed via github. With NVM, one can easily manage and installs multiple versions of Node/NPM on the same server.

Use Case

  • You’re using nvm (Node Version Manager) to manage multiple Node.js versions
  • You want to clean up your system and keep only one version: v22.16.0

Step 1: List All Installed Node Versions

nvm ls

Step 2: Use Bash to Uninstall All But One

Replace the KEEP_VERSION with the version that you want to keep. The following BASH script removes/uninstalls all versions expect the chosen one.

KEEP_VERSION="v22.16.0"

for version in $(nvm ls --no-colors | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | grep -v "$KEEP_VERSION"); do
  echo "Uninstalling $version..."
  nvm uninstall "$version"
done

Explanation

  1. nvm ls --no-colors gives a clean version list
  2. grep -oE extracts valid semantic version numbers
  3. grep -v "$KEEP_VERSION" excludes the version you want to keep
  4. nvm uninstall removes each other version one-by-one

Result

  • Your system now only retains v22.16.0
  • Disk space saved
  • Less version clutter

Tip:

nvm use v22.16.0

to ensure you’re using the correct version after cleanup.

DevOps / Site Reliability Engineering

–EOF (The Ultimate Computing & Technology Blog) —

372 words
Last Post: Last Month's Scam Experience on Telegram (NordVPN Impersonation)
Next Post: PHP7.x is deprecated by WordPress: Why You Should Upgrade to PHP8.x?

The Permanent URL is: How to Clean Up NVM Node Versions Except One? (AMP Version)

Exit mobile version