Skip to content

Instantly share code, notes, and snippets.

@nemanjam
Last active July 8, 2025 18:21
Show Gist options
  • Save nemanjam/c41296abb03eb76eb36c3e687f2fee81 to your computer and use it in GitHub Desktop.
Save nemanjam/c41296abb03eb76eb36c3e687f2fee81 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ChatGpt broken, do not use
# bash <(wget -qO- https://gist.githubusercontent.com/nemanjam/c41296abb03eb76eb36c3e687f2fee81/raw/nvm-latest-lts.sh)
set -e
# Load nvm
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
echo "Installing latest LTS version of Node.js..."
nvm install --lts
# Get latest LTS version number
LATEST_LTS=$(nvm version --lts)
echo "Using and setting default Node.js version to $LATEST_LTS..."
nvm use "$LATEST_LTS"
nvm alias default "$LATEST_LTS"
echo "Uninstalling previously installed Node.js versions (except $LATEST_LTS)..."
for version in $(nvm ls --no-colors | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -u); do
if [ "$version" != "$LATEST_LTS" ]; then
echo "Uninstalling $version..."
nvm uninstall "$version"
fi
done
echo "Enabling corepack to install Yarn and pnpm..."
corepack enable
corepack prepare yarn@stable --activate
corepack prepare pnpm@latest --activate
echo
echo "Versions:"
echo "Node.js: $(node -v)"
echo "Yarn: $(yarn --version)"
echo "pnpm: $(pnpm --version)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment