Skip to content

Instantly share code, notes, and snippets.

@akhdaniel
Last active July 20, 2021 23:03
Show Gist options
  • Save akhdaniel/f24c3341db5ca950a484d0c852f603cc to your computer and use it in GitHub Desktop.
Save akhdaniel/f24c3341db5ca950a484d0c852f603cc to your computer and use it in GitHub Desktop.
Install nodejs 12 with PPA

Install nodejs 12

cd ~
curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs

You may also need development tools to build native addons:

sudo apt-get install gcc g++ make

To install the Yarn package manager, run:

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

An alternative to installing Node.js with apt is to use a tool called nvm, which stands for “Node.js Version Manager”. Rather than working at the operating system level, nvm works at the level of an independent directory within your home directory. This means that you can install multiple self-contained versions of Node.js without affecting the entire system.

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm ls-remote
nvm install 12.18.3
nvm use 12.18.3

If you have multiple Node.js versions, you can see what is installed by typing:

nvm ls

If you wish to default one of the versions, type:

nvm alias default 12.18.3

This version will be automatically selected when a new session spawns. You can also reference it by the alias like this:

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