Skip to content

Instantly share code, notes, and snippets.

@internalsystemerror
Created June 4, 2025 10:29
Show Gist options
  • Select an option

  • Save internalsystemerror/f32260f5c1804be18921055b61ede44a to your computer and use it in GitHub Desktop.

Select an option

Save internalsystemerror/f32260f5c1804be18921055b61ede44a to your computer and use it in GitHub Desktop.
Script to automate updates of LTS Node.js version using NVM
#!/bin/bash
set -euo pipefail
# Load NVM (needed in non-interactive scripts)
export NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
else
echo "ERROR: NVM not found at $NVM_DIR. Is it installed?"
exit 1
fi
# Get current and latest LTS versions
current_version=$(nvm current)
next_version=$(nvm version-remote --lts)
if [ "$current_version" != "$next_version" ]; then
echo "Updating Node.js from $current_version to $next_version"
nvm install $next_version --reinstall-packages-from="$current_version"
nvm uninstall "$current_version"
nvm cache clear
else
echo "Your current version of Node.js ($current_version) is the latest."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment