Created
October 26, 2024 18:38
-
-
Save joeyguerra/1517efc8eef3d27e02aef154b23a7d43 to your computer and use it in GitHub Desktop.
Uninstall all versions of node managed by nvm, except 23.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { execSync } from 'node:child_process' | |
| // Function to execute a shell command and return the output | |
| function execCommand(command) { | |
| return execSync(command, { encoding: 'utf-8' }) | |
| } | |
| // List all installed Node.js versions | |
| const installedVersions = execCommand('. ~/.nvm/nvm.sh && nvm ls --no-colors') | |
| .split('\n') | |
| .map(line => line.trim().match(/^v\d+\.\d+\.\d+/)) | |
| .filter(Boolean) | |
| .filter(line => line !== 'v23.1') | |
| // Uninstall each version except for 23.1 | |
| installedVersions.forEach(version => { | |
| console.log(`Uninstalling: ${version}`) | |
| execCommand(`. ~/.nvm/nvm.sh && nvm uninstall ${version}`); | |
| // console.log(`${version} uninstalled.`); | |
| }) | |
| console.log('All versions except for v23.1 have been uninstalled.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment