Why node and npm version differs?

Viewed 394

Look, I have the latest node version installed

node -v   // I get v14.15.0

Then I runned npm init for a small project. Also I created a index.js file, with the following code

console.lo("Hello") 

obviously it has a typo, it should be console.log("Hello"), but I did this in order to get which version of node and npm is used by the project.

npm ERR! Linux 5.4.0-81-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "npm@next"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /usr/local/lib/node_modules/.staging/@gar/promisify-ebaab35a
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

It is using older versions, but I want the latest. I didn't forced to use an older version So how do I npm init but with newest version of node and npm.

Also when I try to update npm with sudo npm install -g npm@next, I get this error

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@gar/promisify-ebaab35a' -> '/usr/local/lib/node_modules/npm/node_modules/@gar/promisify'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@gar/promisify-ebaab35a' -> '/usr/local/lib/node_modules/npm/node_modules/@gar/promisify'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/braulio/npm-debug.log
npm ERR! code 1

I think that npm is forcing node to use v8.10, so maybe until I don't update npm, node wouldn't. How can I fix this?

1 Answers

Instead of install the node to /usr/bin/node and npm to /usr/bin/npm, you can download node.js linux tarball and decompress them, the node/npm binaries will be available in the bin directory. Then modify your $PATH of current terminal as the following format:

export $PATH=/opt/node-vxx.xx.x/bin/:$PATH
which node
node -v
which npm 
npm -v
Related