Last active
September 10, 2025 18:58
-
-
Save joelkesler/003d888ebef142b65f629ed893fbecb2 to your computer and use it in GitHub Desktop.
NVM Node Upgrade Script (for Bash and Zsh)
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
| #!/bin/bash | |
| # Update Node to selected version | |
| # and reinstall previous packages | |
| # when using NVM | |
| # | |
| # usage: node-upgrade 24 | |
| # | |
| # Tips: | |
| # - To upgrade npm to latest, also run `nvm install-latest-npm` | |
| # - To remove previous version, uncommoment the line with `nvm uninstall "$prev_ver` | |
| # - View all currently installed node versions with `nvm ls` | |
| # | |
| # I recomend adding this to your ~/.bash_profile | |
| node-upgrade() { | |
| new_version=${1:?"Please specify a version to upgrade to. Example: node-upgrade 18"} | |
| nvm install "$new_version" --reinstall-packages-from=current | |
| nvm alias default "$new_version" | |
| # nvm uninstall "$prev_ver" | |
| nvm cache clear | |
| } | |
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
| #!/bin/zsh | |
| # Update Node to selected version | |
| # and reinstall previous packages | |
| # when using NVM | |
| # | |
| # usage: node-upgrade 24 | |
| # | |
| # Tips: | |
| # - To upgrade npm to latest, also run `nvm install-latest-npm` | |
| # - To remove previous version, uncommoment the line with `nvm uninstall "$prev_ver` | |
| # - View all currently installed node versions with `nvm ls` | |
| # | |
| # I recomend adding this to your ~/.zprofile | |
| node-upgrade() { | |
| readonly new_version=${1:?"Please specify a version to upgrade to. Example: node-upgrade 18"} | |
| nvm install "$new_version" --reinstall-packages-from=current | |
| nvm alias default "$new_version" | |
| # nvm uninstall "$prev_ver" | |
| nvm cache clear | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment