How to Install Latest NodeJS and NPM in Linux

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.

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.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

10 thoughts on “How to Install Latest NodeJS and NPM in Linux”

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

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.