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

后端 未结 30 1657
北荒
北荒 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条回答
  • 2020-11-22 08:47

    For Linux, OSX, etc..

    To install the latest version of NPM

    npm install -g npm@latest

    Or To Install the most recent release

    npm install -g npm@next

    Additional : To check your npm version

    npm -v

    If you are in a Windows Machine, I suggest going to the npm website

    0 讨论(0)
  • 2020-11-22 08:47

    Also if you want to update to a particular version, follow this:

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n <specific version>
    
    0 讨论(0)
  • 2020-11-22 08:47

    If you're using Windows: Go to https://nodejs.org/en/download/, download latest .exe or .msi file and install to overwrite the old versions

    If you're using Ubuntu or Linux: Uninstall node.js first then reinstall, e.g with Ubuntu ():

    sudo apt-get remove nodejs
    
    # assume node.js 8 is latest version
    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    sudo apt-get install nodejs
    
    node -v
    npm -v
    

    Remove node_modules in your project folder and npm install to make sure your application will run well on new node and npm version.

    0 讨论(0)
  • 2020-11-22 08:48
    • To update node use nvm (or nvmw for windows).

    • To update npm, the npm update npm -g command didn't work for me (on windows). What did work was reinstalling npm according to the documentation: "You can download a zip file from https://npmjs.org/dist/, and unpack it in the same folder where node.exe lives." Make sure if you do this that you get rid of your previous installation first (though overwriting it will probably work ok...).

    • To update your modules, use the npm update command

    0 讨论(0)
  • 2020-11-22 08:48

    Install npm => sudo apt-get install npm

    Install n => sudo npm install n -g

    latest version of node => sudo n latest

    Specific version of node you can

    List available node versions => n ls

    Install a specific version => sudo n 4.5.0

    0 讨论(0)
  • 2020-11-22 08:50

    See the docs for the update command:

    npm update [-g] [<pkg>...]
    

    This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.

    Additionally, see the documentation on Node.js and NPM installation and Upgrading NPM.

    The following original answer is from the old FAQ that no longer exists, but should work for Linux and Mac:

    How do I update npm?

    npm install -g npm
    

    Please note that this command will remove your current version of npm. Make sure to use sudo npm install -g npm if on a Mac.

    You can also update all outdated local packages by doing npm update without any arguments, or global packages by doing npm update -g.

    Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already. (Consider, if there is ever a bug in the update command.) In those cases, you can do this:

    curl https://www.npmjs.com/install.sh | sh
    

    To update Node.js itself, I recommend you use nvm, the Node Version Manager.

    0 讨论(0)
提交回复
热议问题