sudo: npm: command not found

前端 未结 25 2654
渐次进展
渐次进展 2020-11-28 01:19

I\'m trying to upgrade to the latest version of node. I\'m following the instructions at http://davidwalsh.name/upgrade-nodejs

But when I do:

sudo np         


        
相关标签:
25条回答
  • 2020-11-28 01:37

    In case could be useful for anyone that uses rh-* packages this worked for me:

    sudo ln -s /opt/rh/rh-nodejs8/root/usr/bin/npm /usr/local/bin/npm
    
    0 讨论(0)
  • 2020-11-28 01:38

    For me, any of the methods mentioned above using Homebrew did not work on macOS. So, I uninstalled node using Homebrew and downloaded the node package from https://nodejs.org/en/download/ and installed it. It worked like a charm.

    0 讨论(0)
  • 2020-11-28 01:41

    I had to do the following:

    1. brew update
    2. brew uninstall node
    3. Visit https://nodejs.org/en/ download the file
    4. Install the downloaded file
    0 讨论(0)
  • 2020-11-28 01:42

    WARNING (edit)

    Doing a chmod 777 is a fairly radical solution. Try these first, one at a time, and stop when one works:

    • $ sudo chmod -R 777 /usr/local/lib/node_modules/npm
    • $ sudo chmod -R 777 /usr/local/lib/node_modules
    • $ sudo chmod g+w /usr/local/lib
    • $ sudo chmod g+rwx /usr/local/lib

    $ brew postinstall node is the only install part where I would get a problem

    Permission denied - /usr/local/lib/node_modules/npm/.github
    

    So I

    // !! READ EDIT ABOVE BEFORE RUNNING THIS CODE !!
    $ sudo chmod -R 777 /usr/local/lib
    $ brew postinstall node
    

    and viola, npm is now linked

    $ npm -v
    3.10.10
    

    Extra

    If you used -R 777 on lib my recommendation would be to set nested files and directories to a default setting:

    • $ find /usr/local/lib -type f -print -exec chmod 644 {} \;
    • $ find /usr/local/lib -type d -print -exec chmod 755 {} \;
    • $ chmod /usr/local/lib 755
    0 讨论(0)
  • 2020-11-28 01:43

    I had the same problem; here are the commands to fix it:

    • sudo ln -s /usr/local/bin/node /usr/bin/node
    • sudo ln -s /usr/local/lib/node /usr/lib/node
    • sudo ln -s /usr/local/bin/npm /usr/bin/npm
    • sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
    0 讨论(0)
  • 2020-11-28 01:44

    For CentOS users, this works for me:

    sudo yum install npm
    
    0 讨论(0)
提交回复
热议问题