NPM version I can't update in terminal

I tried some methods but it is not working properly. please refer to image and help me.

kamalkk@kamalkk-Lenovo-G50-80:~$ npm install -g npm@latest
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! dest /usr/local/lib/node_modules/.npm-i9nnxROI
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename ‘/usr/local/lib/node_modules/npm’ → ‘/usr/local/lib/node_modules/.npm-i9nnxROI’
npm ERR! at async Object.rename (node:internal/fs/promises:783:10)
npm ERR! at async moveFile (/usr/local/lib/node_modules/npm/node_modules/@npmcli/fs/lib/move-file.js:30:5)
npm ERR! at async Promise.allSettled (index 0)
npm ERR! at async [reifyPackages] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:246:11)
npm ERR! at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:165:5)
npm ERR! at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:153:5)
npm ERR! at async module.exports (/usr/local/lib/node_modules/npm/lib/cli-entry.js:61:5)
npm ERR! Error: EACCES: permission denied, rename ‘/usr/local/lib/node_modules/npm’ → ‘/usr/local/lib/node_modules/.npm-i9nnxROI’
npm ERR! at async Object.rename (node:internal/fs/promises:783:10)
npm ERR! at async moveFile (/usr/local/lib/node_modules/npm/node_modules/@npmcli/fs/lib/move-file.js:30:5)
npm ERR! at async Promise.allSettled (index 0)
npm ERR! at async [reifyPackages] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:246:11)
npm ERR! at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:165:5)
npm ERR! at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:153:5)
npm ERR! at async module.exports (/usr/local/lib/node_modules/npm/lib/cli-entry.js:61:5) {

Please read the error message line by line and try to understand what it says?

It says as “EACCES: permission denied, rename ‘/usr/local/lib/node_modules/npm’ → ‘/usr/local/lib/node_modules/.npm-i9nnxROI’”

as a normal user, we dont have access to do any changes under /usr/local/lib path.
we have permission to change the files only under our home folder.

To fix your issue, run the same command as root user or with "sudo "

1 Like

Adding to @tshrinivasan comments,
Try to use nvm (node version manager) GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
With this you can hop between different version of npm.

2 Likes

Thanks for your support. Now it’s working good.