Skip to content

Instantly share code, notes, and snippets.

@jmcerrejon
Created October 16, 2021 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcerrejon/babc20b0b66d45844133caa5c46ffaaa to your computer and use it in GitHub Desktop.
Save jmcerrejon/babc20b0b66d45844133caa5c46ffaaa to your computer and use it in GitHub Desktop.
Just install Node.js on Debian. (Tested on Raspberry Pi OS).
#!/bin/bash
#
# Intall Node.js (all versions)
#
install_node() {
local NODE_VERSION
if which node >/dev/null; then
read -p "Warning!: Node.js already installed (Version $(node -v)). Do you want to uninstall it (y/n)?: " option
case "$option" in
y*)
sudo apt-get remove -y nodejs
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
;;
n*) return ;;
esac
fi
cd ~ || exit
if [[ -z "$1" ]]; then
read -p "Type the Node.js version you want to install: 16, 15, 14 (recommended), 13, ...10, followed by [ENTER]: " NODE_VERSION
else
NODE_VERSION="$1"
fi
curl -sL https://deb.nodesource.com/setup_"${NODE_VERSION}".x | sudo -E bash -
echo -e "\nInstalling Node.js and dependencies, please wait...\n"
sudo apt install -y nodejs build-essential libssl-dev libx11-dev
echo -e "\nReboot or logout to use it."
}
# usage: install_node or install_node 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment