-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-nodejs.sh
More file actions
61 lines (51 loc) · 1.73 KB
/
update-nodejs.sh
File metadata and controls
61 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# ============================================================
# Node.js Update Script (RunCloud Guide)
# ============================================================
# Usage:
# 1. Download a script
# wget https://github.com/codetot-web/runcloud-bash-scripts/raw/refs/heads/main/update-nodejs.sh
# 2. Make it executable:
# chmod +x update-node.sh
# 3. Run the script:
# ./update-node.sh
#
# Description:
# - This script updates Node.js to a user-specified version.
# - It prompts you to enter the desired Node.js version (e.g., 20, 22).
# - It removes any existing Node.js installation.
# - It installs the requested version using NodeSource repositories.
# - Finally, it verifies the installation by printing the installed
# Node.js and npm versions.
#
# Notes:
# - Requires sudo privileges.
# - Works on Debian/Ubuntu-based systems.
# - Example input: "20" will install Node.js v20.x.
#
# ============================================================
# Prompt user for desired Node.js version
read -p "Enter the Node.js version you want to install (e.g., 20, 22): " NODE_VERSION
# Validate input
if [[ -z "$NODE_VERSION" ]]; then
echo "No version entered. Exiting."
exit 1
fi
echo "Updating Node.js to version $NODE_VERSION..."
# Update package index
sudo apt update
# Install prerequisites
sudo apt install -y curl software-properties-common
# Remove old Node.js if installed
sudo apt remove -y nodejs
# Add NodeSource repository for chosen version
curl -fsSL https://deb.nodesource.com/setup_$NODE_VERSION.x | sudo -E bash -
# Install Node.js
sudo apt install -y nodejs
# Verify installation
echo "Node.js version installed:"
node -v
echo "npm version installed:"
npm -v
echo "Update complete!"