Node.js: Difference between revisions

From miki
Jump to navigation Jump to search
(Created page with "== Install == The simplest is to install from apt: <source lang="bash"> sudo apt install nodejs npm </source> To install the latest version using apt, install Node.js reposit...")
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Node.js]] is the open-source JavaScript runtime environment based on Chrome V8 engine and that can execute JavaScript code outside a web browser.

== References ==
* https://nodejs.org/en/ &mdash; Node.js home (show current LTS version, and latest version).
* [https://nodejs.org/en/download/package-manager/ Install Node.js via package manager] &mdash; Apt, Nvm...
:* [https://github.com/nvm-sh/nvm NVM] &mdash; Node Version Manager, which allows to manage multiple released Node.js versions (to use version from source, see [https://nodejs.org/en/download/package-manager/#nvm here]).

== Install ==
== Install ==
=== Install using distribution packages ===
The simplest is to install from apt:
The simplest is to install from apt:
<source lang="bash">
<source lang="bash">
Line 10: Line 18:
# Add repository -- adapt version as necessary:
# Add repository -- adapt version as necessary:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# ...
# ## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
# ## 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

# Install
# Install
sudo apt install nodejs
sudo apt install nodejs
</source>
</source>

=== Install using NVM ===
See instruction on [https://github.com/nvm-sh/nvm github].
<source lang="bash">
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
</source>

Example of use
<source lang="bash">
nvm use 16
# Now using node v16.9.1 (npm v7.21.1)
node -v
# v16.9.1
nvm use 14
# Now using node v14.18.0 (npm v6.14.15)
node -v
# v14.18.0
nvm install 12
# Now using node v12.22.6 (npm v6.14.5)
node -v
# v12.22.6
</source>

== Installing packages with NPM ==
See [[NPM]].

Latest revision as of 16:03, 1 November 2021

Node.js is the open-source JavaScript runtime environment based on Chrome V8 engine and that can execute JavaScript code outside a web browser.

References

  • NVM — Node Version Manager, which allows to manage multiple released Node.js versions (to use version from source, see here).

Install

Install using distribution packages

The simplest is to install from apt:

sudo apt install nodejs npm

To install the latest version using apt, install Node.js repositories (nodesource, [

# Add repository -- adapt version as necessary:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# ...
# ## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
# ## 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

# Install
sudo apt install nodejs

Install using NVM

See instruction on github.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

Example of use

nvm use 16
# Now using node v16.9.1 (npm v7.21.1)
node -v
# v16.9.1
nvm use 14
# Now using node v14.18.0 (npm v6.14.15)
node -v
# v14.18.0
nvm install 12
# Now using node v12.22.6 (npm v6.14.5)
node -v
# v12.22.6

Installing packages with NPM

See NPM.