7

First, I install npm

sudo apt-get install -y npm

Which installs npm version 3.5.2. Then I try to update it to newest version and it fails. Could not find a proper solution for this.

sudo npm install npm@latest -g
▌ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine npm@7.5.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine npm@7.5.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":/usr/local/lib
└── (empty)

npm ERR! Linux 4.15.0-135-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "npm@latest" "-g"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552' -> '/usr/local/lib/node_modules/npm/node_modules/@npmcli/ci-detect'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552' -> '/usr/local/lib/node_modules/npm/node_modules/@npmcli/ci-detect'
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/some/path/npm-debug.log
npm ERR! code 1
user2340939
  • 183
  • 1
  • 6
  • 1
    In addition to answering how to install node on top of the OS, it would be interesting to know how such a breakage can just start happening out of the blue. Is there a safe npm to try to update to? – nicomen Feb 05 '21 at 16:39
  • If you want a more recent version, consider installing Node not from Ubuntu's official package sources but directly from NodeSource or using NVM or (better) FNM. – Daniel B Feb 10 '21 at 11:22

4 Answers4

8

This is a result of: https://github.com/npm/cli/issues/2599

If you're happy using npm version 6 (current lts) then you can just run:

sudo npm install -g npm@latest-6

to install the latest version 6, this saves you involving another package manager.

RoperMaps
  • 181
  • 2
6

I had the exact same issue, after some research I found this post. Several options are given in this article, Option 1 with nvm installation worked for me.

sudo apt update

sudo apt install build-essential checkinstall libssl-dev

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.1/install.sh | bash

nvm --version

nvm ls-remote

nvm install [version.number]

More info in this post: https://phoenixnap.com/kb/update-node-js-version

2

What worked for me was to install using n, Node’s version manager

npm install -g n

Then I installed the latest version using

n latest
nomulex
  • 121
  • 2
0

In my case it was giving me that error when trying to update the version of npm, it had version 3.5.2 and when I put sudo npm install -g npm@latest.

I wanted to update to 6.14.8 and I did it with sudo npm install -g npm@6.14.8

after installing when putting npm --version it kept showing 3.5.2 I closed the terminal and in another session it showed version 6.14.8 fine

Jaime Roman
  • 101
  • 1