How to Install Node.js and npm on Debian 9
Node.js is an open-source cross-stage JavaScript run-time climate based on Chrome's JavaScript motor that permits worker side execution of JavaScript code. It is chiefly used to construct worker side applications, however it is likewise famous as a full-stack and front-end arrangement. npm is the default bundle director for Node.js and the world's biggest programming library.
In this instructional exercise, we will cover how to introduce Node.js and npm on Debian 9. We will show both of you various approaches to introduce Node.js on Debian. Pick the establishment choice that is best for you.
Install Node.js and NPM from the NodeSource repository
The most effortless approach to introduce the most recent forms of Node.js and npm is to introduce the bundle from the archive kept up by NodeSource.
To add the NodeSource store to your framework run the accompanying order:
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
The current LTS variant of Node.js is form 8.x, Carbon. On the off chance that you need to introduce Node.js variant 10.x simply change setup_8.x with setup_10.x
When the NodeSource store is added introduce Node.js and npm with the accompanying order:
sudo apt install nodejs
To confirm if the establishment was fruitful, print the Node.js and npm adaptations:
node --version
v8.11.3
npm --version
5.6.0
Install Node.js and NPM using NVM
NVM (Node Version Manager) is a slam content that permits you to deal with numerous Node.js forms. With NVM you can introduce and uninstall a particular Node.js variant that you need to utilize or test.
Download the nvm introduce content with the accompanying twist order :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
The establishment content clones the nvm store from Github to the ~/.nvm index and adds the nvm way to your Bash or ZSH profile.
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
As the yield above proposes, you can either open another shell meeting or run the orders to add the way to the nvm content to your present meeting. Do whatever is simpler for you.
To guarantee that nvm is appropriately introduced type:
nvm --version
0.33.11
Since you have nvm introduced on your Debian machine, to introduce the most recent accessible variant of Node.js, type:
nvm install node
Downloading and installing node v10.5.0...
Downloading https://nodejs.org/dist/v10.5.0/node-v10.5.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.5.0 (npm v6.1.0)
Creating default alias: default -> node (-> v10.5.0)
Check the Node.js adaptation, by composing:
node --version
v10.5.0
We should introduce two additional renditions, the most recent LTS form and form 6.14.3:
nvm install --lts
nvm install 6.14.3
When LTS form and 6.14.3 are introduced we can list introduced Node.js examples by composing:
nvm ls
-> v6.14.3 # ACTIVE VERSION
v8.11.3
v10.5.0
system
default -> node (-> v10.5.0) # DEFAULT VERSION
node -> stable (-> v10.5.0) (default)
stable -> 10.5 (-> v10.5.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.3)
lts/argon -6.14.3:(-> N/A)
lts/boron -> v6.14.3
lts/carbon -> v8.11.3
In the yield over, the section with a bolt on the privilege (- > v6.14.3), is the variant utilized in the current shell meeting and the default adaptation is set to v10.5.0.
The default form is the rendition that will be utilized when you open new shell meetings.
On the off chance that you need to change the presently dynamic variant utilize the accompanying order:
nvm use 8.11.3
what's more, confirm it by composing:
nvm current
v8.11.3
To set rendition 8.11.3 as the default Node.js form type:
nvm alias default 8.11.3
Install development tools
To incorporate and introduce local additional items from the npm library you need to introduce the improvement devices.
sudo apt install build-essential
Uninstall Node.js
In the event that for certain reasons you need to uninstall Node.js and npm bundles, you can utilize the accompanying order:
sudo apt remove nodejs npm
Conclusion
We have indicated both of you various approaches to introduce Node.js and npm on your Debian 9 worker. The strategy you pick relies upon your prerequisites and inclinations. Despite the fact that introducing the bundled adaptation from the NodeSource archive is simpler, the nvm technique gives you greater adaptability for adding and eliminating diverse Node.js renditions on a for every client premise.
Since you've introduced Node.js on your Debian 9 framework, it's an ideal opportunity to begin building up your application!
On the off chance that you need to deal with your npm bundles with yarn, you can check this instructional exercise about how to introduce and utilize yarn on Debian 9 .
On the off chance that you have any inquiries or criticism, don't hesitate to remark beneath.