How can I update NodeJS and NPM to the next versions?

后端 未结 30 1670
北荒
北荒 2020-11-22 08:07

I just installed Node.js and npm (for additional modules).

How can I update Node.js and the modules which I\'m using to the latest versions

30条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 08:50

    Use n module from npm in order to upgrade node . n is a node helper package that installs or updates a given node.js version.

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n stable
    sudo ln -sf /usr/local/n/versions/node//bin/node /usr/bin/nodejs
    

    NOTE that the default installation for nodejs is in the /usr/bin/nodejs and not /usr/bin/node

    To upgrade to latest version (and not current stable) version, you can use

    sudo n latest

    To undo:

    sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
    sudo n rm 6.0.0     # replace number with version of Node that was installed
    sudo npm uninstall -g n
    

    If you get the following error bash: /usr/bin/node: No such file or directory then the path you have entered at

    sudo ln -sf /usr/local/n/versions/node//bin/node /usr/bin/nodejs
    

    if wrong. so make sure to check if the update nodejs has been installed at the above path and the version you are entered is correct.

    I would advise strongly against doing this on a production instance. It can seriously mess stuff up with your global npm packages and your ability to install new one.

提交回复
热议问题