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
nvm ls --no-colorsgives a clean version listgrep -oEextracts valid semantic version numbersgrep -v "$KEEP_VERSION"excludes the version you want to keepnvm uninstallremoves 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
- How to Clean Up NVM Node Versions Except One?
- Monitoring 28 VPS Machines including a Raspberry Pi with Nezha Dashboard
- Python/Bash Script to Print the Optimized Parameters for MySQL Servers
- Learn to Manage Your MySQL Database with a Python Script
- A Simple PHP Command Line Tool to Convert MySQL Tables from MyISAM to InnoDB in Specified Database
- How to Print MySQL Table Summary using PHP?
- Secure the Linux Server by Disallow the Remote Root Login (SSH and FTP and MySQL database)
- Bash Script to Check, Repair, Optimise and Backup MySQL database
- Duplicate a MySQL table - Copy Table / Duplicate Database / PHP Script
- MySQL server stopped due of out of memory exception on Ubuntu VPS
- Running Apache Server (PHP + MySQL) on Raspberry PI
- How to Optimise SQL Queries? Quick Tips
- Recovery Models in SQL Server
- Database Optimisation Script in PHP
–EOF (The Ultimate Computing & Technology Blog) —
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?
