These scripts install or upgrade Node.js from the official binaries on Linux systems. They support installing specific versions or the latest in a major version series, automatically detect the system architecture, and handle version conflicts.
- Version Selection: Install a specific Node.js version (e.g.,
v18.17.0) or the latest in a major series (e.g.,20for the newest 20.x version). - Architecture Detection: Automatically detects x86_64, ARM64, ARMv7, etc., and downloads the appropriate binary.
- Conflict Resolution: Removes existing Node.js installations if they differ from the requested version.
- Symlinks: Creates symbolic links for
node,npm,npx, andnodejscommands in/usr/local/bin. - Verification: Tests all installed binaries after installation.
- Logging: Logs all operations to
/var/log/node_install.log.
The upgrade script uses the same version selection rules as the installer, but it removes any existing node-* directories from /opt before installing the requested version.
sudo ./upgrade_nodeJs.sh [version]The upgrade log is written to /var/log/node_upgrade.log.
sudo ./setup_nodeJs.sh [version]version: Optional. Can be:- A full version string (e.g.,
v18.17.0) - A major version number (e.g.,
20) to install the latest in that series - If omitted, installs the latest LTS version
- A full version string (e.g.,
# Install the latest LTS version
sudo ./setup_nodeJs.sh
# Install the latest in Node.js 20.x series
sudo ./setup_nodeJs.sh 20
# Install a specific version
sudo ./setup_nodeJs.sh v18.17.0- Purge System Packages: Removes any system-installed
nodejsandnpmpackages to avoid conflicts. - Version Resolution: Determines the exact version to install based on input.
- Architecture Check: Detects the system architecture and selects the correct binary.
- Download: Fetches the Node.js tarball from
nodejs.org. - Extraction: Extracts to
/opt/node-{version}-linux-{arch}/. - Cleanup: Removes the downloaded tarball.
- Symlinks: Creates symlinks in
/usr/local/binfor easy access. - Testing: Verifies all commands work and logs versions.
- Binaries:
/opt/node-{version}-linux-{arch}/bin/ - Symlinks:
/usr/local/bin/(points to the above) - Log File:
/var/log/node_install.log
- Ensure you're running with
sudo. - Check that
/var/log,/opt, and/usr/local/binare writable by root.
- Verify internet connection.
- Check if the requested version exists on nodejs.org/dist/.
- For major versions, ensure there are releases in that series.
- The script supports x86_64, ARM64, and ARMv7.
- Unknown architectures fall back to x64 with a warning.
- Install
jq:sudo apt install jq(on Debian/Ubuntu).
- The script only removes installations with different versions.
- If the same version is requested, it overwrites the existing install.
To remove Node.js installed by this script:
sudo rm -rf /opt/node-*
sudo rm /usr/local/bin/node /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/nodejsThis script is part of the Shell Script Utilities collection. See the main README for more information. /home/jonas/Git/Shell_Script_Utilities/Program_Setups/README.md