Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Last active October 5, 2023 16:37
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexbosworth/8fad3d51f9e1ff67995713edf2d20126 to your computer and use it in GitHub Desktop.
Save alexbosworth/8fad3d51f9e1ff67995713edf2d20126 to your computer and use it in GitHub Desktop.
Setup NPM

Install make

You will probably need build essential tools

# Ubuntu install build tools:
sudo apt-get install -y build-essential

Install Node.js

Node installation instructions

The instructions for Ubuntu/Debian:

# confirm the version of Ubuntu is supported
lsb_release -a
# should show Ubuntu version 20 or higher

# Update APT
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

# Get repo for Node.js version 20
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

# Install Node.js
sudo apt-get update
sudo apt-get install nodejs -y

Setup NPM

Avoid having to use sudo with npm on Ubuntu:

# Make a local directory for NPM
mkdir ~/.npm-global

# Configure NPM to use npm-global for non-root access
npm config set prefix '~/.npm-global'

# Add .npm-global/bin to $PATH
# Change ~/.profile to ~/.zshrc if you are running in zsh shell like on macos
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.profile

# Update the local $PATH (don't forget the leading . with a space after it)
. ~/.profile
@Kixunil
Copy link

Kixunil commented Mar 26, 2021

Please do not recommend users to use https://deb.nodesource.com/setup_12.x. It can break the system, as happened to a friend, and is generally less secure than installation from Debian/Ubuntu packages.

Simple apt install nodejs is enough. The version in Debian stable is supported by bos, so there's no problem. Users with older system should just upgrade the OS instead of making "franken Debian".

Ubuntu generally has newer packages than Debian stable, so the same applies in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment