Install NPM and NodeJS

I know it is not a Rocky Linux problem. I need a little help to install and update Nodejs and npm. I want to install Gatsby.

That I have done:

dnf module list nodejs
dnf module installl nodejs:16
npm install -g npm@8.9.0
npm install -g gatsby-cli

This are the error messages:

npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher
npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN deprecated async-cache@1.1.0: No longer maintained. Use [lru-cache](http://npm.im/lru-cache) version 7.6 or higher, and provide an asynchronous `fetchMethod` option.
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated devcert@1.2.0: critical regex denial of service bug fixed in 1.2.1 patch
npm WARN deprecated subscriptions-transport-ws@0.9.19: The `subscriptions-transport-ws` package is no longer maintained. We recommend you use `graphql-ws` instead. For help migrating Apollo software to `graphql-ws`, see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws    For general help using `graphql-ws`, see https://github.com/enisdenjo/graphql-ws/blob/master/README.md

It’s worth noting that those four commands comprise two different things.

The first two related to installing nodejs using the official Rocky repos, and as I understand it, there were no errors with that part? The second two commands are trying to install things that are not part of Rocky; npm itself maybe, but who knows if those other packages are safe?

Hi Joerg,

Just relax, it has no error at all, those messages just tell you that you have out-dated packages installed. Run command ‘npm audit’ (you may need super user right to do it), and follow the output instructions to update your packages.

Remark: The default version of node.js of Rocky Linux is 14.x, you better switch the node.js on your system to version 16.x by following commands;

dnf module reset nodejs
dnf module enable nodejs:16

Cheers,
Athens

1 Like

An alternative is to use n which will let you keep and manage multiple versions…

Eg. updating to current LTS releases…

# dnf -y install nodejs 
...
# node --version
v10.24.0
# npm --version
6.14.11
...
# npm install -g n
# n lts
  installing : node-v16.15.1
       mkdir : /usr/local/n/versions/node/16.15.1
       fetch : https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.xz
     copying : node/16.15.1
   installed : v16.15.1 (with npm 8.11.0)

Note: the node command changed location and the old location may be remembered in your current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r  (for bash, zsh, ash, dash, and ksh)
rehash   (for csh and tcsh)
...
exit/reenter shell...(only necessary first time n is run (?))
# node --version
v16.15.1
# npm --version
8.11.0
# n 10.24.0
  installing : node-v10.24.0
       mkdir : /usr/local/n/versions/node/10.24.0
       fetch : https://nodejs.org/dist/v10.24.0/node-v10.24.0-linux-x64.tar.xz
     copying : node/10.24.0
   installed : v10.24.0 (with npm 6.14.11)
# node --version
v10.24.0
# npm --version
6.14.11
# n lts
     copying : node/16.15.1
   installed : v16.15.1 (with npm 8.11.0)
# npm --version
8.11.0
# node --version
v16.15.1

But when you apply security updates to Rocky, make sure any alternate versions are also patched.