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.

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.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

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.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.