YouTube Icon

Code Playground.

How to Install Node.js and npm on CentOS 8

CFG

How to Install Node.js and npm on CentOS 8

Node.js is a cross-stage JavaScript runtime climate based on Chrome's JavaScript intended to execute JavaScript code on the worker side. With Node.js, you can manufacture versatile organization applications. 

npm, short for Node Package Manager is the default bundle administrator for Node.js that encourages engineers to share and reuse their code. It likewise alludes to the world's biggest programming archive for the distributing of open-source Node.js bundles 

In this article, we will walk you through two unique approaches to introduce Node.js and npm on CentOS 8. Pick the establishment alternative that may be generally fitting for your current circumstance. 

Installing Node.js and npm from the CentOS repositories

Node.js and npm can be introduced from the standard CentOS stores. At the hour of composing, the Node.js adaptation in the stores is v10.x. 

Rundown the modules that give the nodejs bundle by running the accompanying order: 

yum module list nodejs

The yield shows that the nodejs module is accessible with just one stream. Stream 10 speaks to the Node.js rendition. 

CentOS-8 - AppStream
Name      Stream    Profiles                                Summary             
nodejs    10 [d]    common [d], development, minimal, s2i   Javascript runtime 

The nodejs bundle gives four unique profiles. The default profile, the one set apart with [d] introduces a typical arrangement of runtime bundles. 

To introduce the default Node.js bundle on your CentOS framework, type: 

sudo yum module install nodejs

The order above additionally introduces NPM. 

In the event that you are an engineer, introduce the improvement profile, which likewise introduces extra libraries important to manufacture progressively loadable modules. 

sudo yum module install nodejs/development

One the establishment is finished, confirm it by composing: 

node --version

The order shows the Node.js adaptation: 

v10.16.3

This is the least demanding approach to introduce Node.js and npm on CentOS 8 and ought to be adequate for most use cases. 

Installing Development Tools

The advancement apparatuses are important for incorporating and introducing local additional items from the npm library. Introduce the bundle by running: 

sudo dnf groupinstall 'Development Tools'

Uninstalling Node.js

In the event that for certain reasons you need to uninstall Node.js and npm bundles, utilize the accompanying order: 

sudo yum module install nodejs

Installing Node.js and npm using NVM

NVM (Node Version Manager) is a slam content that permits you to deal with various Node.js variants on a for every client premise. With NVM you can introduce and uninstall any Node.js variant that you need to utilize or test. 

To introduce NVM on your CentOS framework, run the order underneath. Try not to utilize sudo as it will empower the content for the root client. 

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 catalog and adds the nvm way to your Bash or ZSH profile. 

...
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

To begin utilizing the nvm content, either open another shell meeting or run the orders imprinted on your screen. Do whatever is simpler for you. 

Presently that the nvm content is empowered on your CentOS, you can introduce the most recent stable form of Node.js with: 

nvm install node
...
Computing checksum with sha256sum
Checksums matched!
Now using node v13.0.1 (npm v6.12.0)
Creating default alias: default -> node (-> v13.0.1)

We should introduce two additional forms, the most recent LTS variant and rendition 10.16.0: 

nvm install --lts
nvm install 10.16.0

When the establishment is finished, you can list all introduced Node.js adaptations by composing: 

nvm ls
->     v10.16.0
       v12.13.0
        v13.0.1
default -> node (-> v13.0.1)
node -> stable (-> v13.0.1) (default)
stable -> 13.0 (-> v13.0.1) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.2 (-> N/A)
lts/dubnium -> v10.17.0 (-> N/A)
lts/erbium -> v12.13.0

The section with a bolt on the privilege (- > v10.16.0), is the rendition utilized in the current shell meeting. The default variant which is utilized when you open new shell meetings is set to v13.0.1. 

On the off chance that you need to change the as of now dynamic form, suppose to v12.13.0 you would run: 

nvm use v12.13.0

To change the default Node.js, to v12.13.0 use: 

nvm alias default v12.13.0

Conclusion

We have demonstrated both of you various approaches to introduce Node.js and npm on CentOS 8. The strategy you pick relies upon your necessities and inclinations. 

Since you've introduced Node.js on your CentOS 8 framework, it's an ideal opportunity to convey your application. 

In the event that you need to utilize Yarn to deal with your application conditions, check our instructional exercise on the most proficient method to introduce and utilize yarn on CentOS 8 . 

In the event that you have any inquiries or input, don't hesitate to remark beneath.




CFG