Skip to content

Instantly share code, notes, and snippets.

@joelkesler
Last active September 10, 2025 18:58
Show Gist options
  • Select an option

  • Save joelkesler/003d888ebef142b65f629ed893fbecb2 to your computer and use it in GitHub Desktop.

Select an option

Save joelkesler/003d888ebef142b65f629ed893fbecb2 to your computer and use it in GitHub Desktop.
NVM Node Upgrade Script (for Bash and Zsh)
#!/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
}
#!/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