npm install npm -g won't update npm to the latest version

前端 未结 6 1328
刺人心
刺人心 2021-02-19 06:17

I am using npm v5.3.0. Now I want to update npm to v5.4.1.To do this I type the following in my terminal:

npm install -g npm

without any errors.Howe

6条回答
  •  猫巷女王i
    2021-02-19 06:58

    I had to dig a little bit more (probably I have some misconfig) and take an hardcore approach... First I ran which npm to get the script that was running, that was /usr/local/opt/node@8/bin/npm.js. From that script I saw that the npm package was actually in /usr/local/opt/node@8/lib/node_modules/npm. So I ran

    cd /usr/local/opt/node@8/lib/
    npm i npm@6.11.2 # or your desired version
    rm package-lock.json # clean up
    

    And that did the trick, hope it helps someone :)

    NB: I'm not saying that you should do this right away, first is better if you try the other approaches but if other approaches are not working give it a shot

提交回复
热议问题