diff --git a/misc/tools.func b/misc/tools.func index 48264e356..0faed120a 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -3322,13 +3322,25 @@ function setup_nodejs() { # Clean up legacy installations (nvm, etc.) cleanup_legacy_install "nodejs" - # Remove Debian's nodejs if present (conflicts with NodeSource) - if dpkg -l | grep -q "^ii.*nodejs.*dfsg"; then - $STD msg_info "Removing Debian-packaged Node.js (conflicts with NodeSource)" - $STD apt purge -y nodejs libnode* 2>/dev/null || true + # Set APT priority FIRST to prevent Debian nodejs from being installed + cat >/etc/apt/preferences.d/nodesource <<'EOF' +Package: nodejs +Pin: origin deb.nodesource.com +Pin-Priority: 600 + +Package: * +Pin: origin deb.nodesource.com +Pin-Priority: 600 +EOF + + # Remove any existing Debian nodejs BEFORE adding NodeSource repo + if dpkg -l 2>/dev/null | grep -q "^ii.*nodejs"; then + msg_info "Removing Debian-packaged Node.js (conflicts with NodeSource)" + $STD apt purge -y nodejs nodejs-doc libnode* node-* 2>/dev/null || true $STD apt autoremove -y 2>/dev/null || true fi + # Install dependencies (now protected by APT pinning) ensure_dependencies curl ca-certificates gnupg # Prepare repository (cleanup + validation) @@ -3343,17 +3355,6 @@ function setup_nodejs() { return 1 } - # Set APT priority to prefer NodeSource over Debian repos - cat >/etc/apt/preferences.d/nodesource <<'EOF' -Package: nodejs -Pin: origin deb.nodesource.com -Pin-Priority: 600 - -Package: * -Pin: origin deb.nodesource.com -Pin-Priority: 600 -EOF - # Wait for repo to settle sleep 2