VOOZH about

URL: https://www.tecmint.com/install-nodejs-npm-in-centos-ubuntu/

⇱ How to Install Node.js and NPM in RHEL and Debian Systems


Skip to content

In this guide, we shall take a look at how you can install the latest version of Nodejs and NPM on RHEL-based distributions such as CentOS, Fedora, Rocky & AlmaLinux and Debian-based distributions such as Ubuntu & Linux Mint.

[ You might also like: NVM – Install and Manage Multiple Node.js Versions in Linux ]

Nodejs is a lightweight and efficient JavaScript platform that is built based on Chrome’s V8 JavaScript engine and NPM is a default NodeJS package manager. You can use it to build scalable network applications.

How to Install Node.js in RHEL Distributions

The latest version of Node.js and NPM is available from the official NodeSource Enterprise Linux repository, which is maintained by the Nodejs website and you will need to add it to your system to be able to install the latest Nodejs and NPM packages.

Important: If you are running an older release of RHEL 6 or CentOS 6, you might want to read about running Node.js on older distros.

Installing NodeJS in RHEL, CentOS, Fedora, Rocky & Alma

To add the repository for the latest version of Node.js, use the following command as root or non-root.

------------- For Node.js v19.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_19.x | sudo bash -
$ sudo yum install -y nodejs

------------- For Node.js v18.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
$ sudo yum install -y nodejs

------------- For Node.js v16.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
$ sudo yum install -y nodejs

------------- For Node.js v14.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_14.x | sudo bash -
$ sudo yum install -y nodejs

Optional: There are development tools such as gcc-c++ and make that you need to have on your system, in order to build native addons from npm.

# yum install gcc-c++ make
OR
# yum groupinstall 'Development Tools'

How to Install Node.js in Debian, Ubuntu, and Linux Mint

The latest version of Node.js and NPM is also available from the official NodeSource Enterprise Linux repository, which is maintained by the Nodejs website and you will need to add it to your system to be able to install the latest Nodejs and NPM packages.

Install Node.js on Ubuntu and Mint

------------- For Node.js v19.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v18.x -------------
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v16.x -------------
$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v14.x -------------
$ curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

Install Node.js on Debian

------------- For Node.js v19.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_19.x | bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v18.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v16.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v14.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_14.x | bash - &&\
$ sudo apt-get install -y nodejs

Optional: There are development tools such as gcc-c++ and make that you need to have on your system, in order to build native addons from npm.

$ sudo apt-get install -y build-essential

Testing Latest Nodejs and NPM in Linux

To have a simple test of nodejs and NPM, you can just check the versions installed on your system by using the following commands:

On RHEL-based Systems

# node --version
# npm --version

On Debian, Ubuntu, and Linux Mint

$ nodejs --version
$ npm --version
πŸ‘ Check NodeJS Version in CentOS
Check NodeJS Version on CentOS

That is it, Nodejs and NPM are now installed and ready for use on your system.

I believe these were easy and simple steps to follow but in case of problems you faced, you can let us know and we find ways of helping you. I hope this guide was helpful to you and always remember to stay connected to Tecmint.

If this article helped, share it with someone on your team.
TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
β˜•
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
β˜• Buy Me a Coffee
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

10 Comments

Leave a Reply
  1. Trying to install nodejs.

    E: Could not open lock file /var/lib/apt/lists/lock – open (13: Permission denied)
    E: Unable to lock directory /var/lib/apt/lists/
    W: Problem unlinking the file /var/cache/apt/pkgcache.bin – Remove Caches (13: Permission denied)
    W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin – Remove caches (13: Permission denied)

    Reply
    • @AlienF,

      Remove the lock file

      $ sudo rm /var/lib/apt/lists/lock
      

      Then run the command again as root user.

      Reply
  2. I tried to load nodejs into RPi 3B+ w/ raspbian Deb.

    Some errors:

    Get:1 https://deb.nodesourcs.com/node_14.x bullseye/main armhf 
    nodejs armhf 14.18.-deb-1nodesourse1 {22.9mb}
    Fetched 22.9mb in 26s (873 kb/s)
    apt-listchanges: can't set locale: make sure SLC-* and Slang are correct!
    perl: warning: Setting locale failed.
    perl: warning: Please check your locale settings
    LANGUAGE = (unset),
    LC_all = (unset),
    LANG = "en_GB.UTF-8" are supported on you system.
    perl: warning: Falling back to the standard locale ("C")
    

    Also,

    $ nodejs --version bash: nodejs: command not found.
    $ npm --version 6.14.15
    

    What is wrong here and how do I fix it?

    Thanks
    AllenF

    Reply
    • @AlienF,

      Try these commands to fix the error.

      $ export LC_ALL="en_US.UTF-8"
      $ sudo dpkg-reconfigure locales
      
      Reply
      • That seemed to help. Thanks. I am going to try to reload nodejs
        Allen

        Reply
  3. svm you could install, so you could install multiple versions.

    Reply
  4. I already have node 8.12 on my Fedora 27. I would like to UPGRADE it to the newest version. Is that possible and if so how do I do it.

    Or do I need to uninstall and then reinstall the new one

    Reply
    • @Ken,

      Yes, that’s possible, just follow the instructions given in the article to upgrade to the latest Node.js version.

      Reply
  5. It’s not latest, you have added setup_11.x and setup_10.x but it is installing 6.x.

    Reply
    • @Siraj,

      I think you already have 6.x repository enabled, remove that and re-install the new 11.x repo and see..

      Reply

Got Something to Say? Join the Discussion... Cancel reply

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Check your email for a magic link to get started.