To install Node.js version 9.x on a Linux system, execute the installation script with the command curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
and then update the package index with sudo apt-get update -qqy
.
npm run import -- "install node"
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - \
&& sudo apt-get update -qqy \
&& sudo apt-get -qqy install nodejs build-essential
bash
#!/bin/bash
# Install Node.js 9.x via nodesource repository
# https://github.com/nodesource/distributions/blob/master/README.md#installing-nodejs-and-npm-from-source-using-compiled-binary-tarball-or-from-source-with-gcc
# Define the installation script URL
NODE_SETUP_URL='https://deb.nodesource.com/setup_9.x'
# Download the installation script and pass it to bash for execution
curl -sfL "$NODE_SETUP_URL" | sudo -E bash -
# Update the package list
sudo apt-get update -qqy
# Install Node.js and build-essential
sudo apt-get -qqy install nodejs build-essential
# TODO: Consider using a more robust error handling mechanism, e.g., trap and set -e
# TODO: Refactor code to use functions for better modularity and reusability
Code Breakdown
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - \
curl
: download a file from a web URL-sL
: silent mode and follow redirectshttps://deb.nodesource.com/setup_9.x
: download the installation script for Node.js version 9.x from NodeSourcesudo -E bash -
: execute the downloaded script with elevated privileges and keep environment variablessudo apt-get update -qqy
sudo apt-get update
: update the package index with elevated privileges-qqy
: quiet mode for progress updates and enable all required packages to be installedsudo apt-get -qqy install nodejs build-essential
sudo apt-get install
: install packages with elevated privileges-qqy
: quiet mode for progress updates and enable all required packages to be installednodejs
: install Node.jsbuild-essential
: install build essential packages (e.g. gcc, make, etc.)