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

后端 未结 30 1654
北荒
北荒 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 09:00

    Just run the following command in terminal as root/administrator:

    npm i -g n
    n stable
    npm update -g npm
    

    It has worked for me on Linux

    0 讨论(0)
  • 2020-11-22 09:02

    I recently stumbled across this article: http://martineau.tv/blog/2013/12/more-efficient-grunt-workflows/ and the author mentions $ npm-check-updates -u && npm install to update all dependencies.

    This is a little off the topic but I ended up here on a similar search so thought it was worth the share.

    0 讨论(0)
  • 2020-11-22 09:03
    $ npm install -g npm stable
    

    Worked for me to update from 1.4.28 to 2.1.5

    0 讨论(0)
  • 2020-11-22 09:04

    I found this really neat way of updating node on David Walsh's blog, you can do it by installing n:

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n stable
    

    It will install the current stable version of node.


    EDIT: Please don't use n anymore. I recommend using nvm. You can simply install stable by following the commands below:

    nvm ls-remote
    nvm install <version> 
    nvm use <version>
    
    0 讨论(0)
  • 2020-11-22 09:05

    For Cygwin users:

    Installing n (node version manager) in Cygwin doesn't work, instead update node with:

    wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\pathto\nodejs\node.exe'
    # Updating npm
    npm i -g npm
    

    Yes, you need to install wget first.

    0 讨论(0)
  • 2020-11-22 09:06

    As you may already know, npm is currently bundled with node.js. It means that if you have installed node.js, you've already installed npm as well.

    Also, pay attention to the node.js and npm release versions table that shows us approximate versions compatibility. Sometimes, versions discrepancy may cause incompatibility errors.

    So, if you're a developer, it's kinda "best practice" to manage your development environment using one of the node.js version managers.

    Here is a list and usage notes of some of the most popular:

    Homebrew (macOS)

    If you're on macOS, you can use Homebrew.

    Actually, it's not just a node.js version manager.

    To install Homebrew to your Mac:

    $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    

    To install node.js and npm using Homebrew, run:

    $ brew install node
    

    Later, you will be able to update them using:

    $ brew update && brew upgrade node
    

    Also, you can switch between node.js versions as well:

    $ brew switch node 0.10.26
    

    npm will be upgraded/downgraded automatically.

    n (macOS, Linux)

    n is most likely to rvm (Ruby Version Manager), and is used to manage node.js and npm versions simultaneously. It is written on pure Linux shell, and available as an npm module. So, if you already have any node.js version installed, you can install/update the n package through npm:

    $ npm install -g n
    

    Downloading, installing and switching to node.js and npm versions is as easy as:

    $ n 0.10.26
    $ n 0.8.17
    $ n 0.9.6
    

    To download, install, and switch to the latest official release, use:

    $ n latest
    

    To download, install, and switch to the latest stable official release, use:

    $ n stable
    

    To switch to the previously active version (aka $ cd -), use:

    $ n prev
    

    If you want to see the list of installed node.js versions, just run n from your command line. The output will be something like the following:

    $ n
    
      0.10.26
    • 0.8.17
      0.9.6
    

    Where the dot (•) means that it's a currently active version. To select another node.js version from the list, use Up/Down arrow keys and activate using the Enter key.

    To list the versions available to install:

    $ n lsr
    

    nvm (macOS, Linux)

    nvm is also like rvm, even the command names and usage are very similar.

    To install nvm you can use the installation script (requires git) using cURL:

    $ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
    

    or wget:

    $ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
    

    To download and install a specific node.js and npm version, use:

    $ nvm install 0.10
    

    Then, you can switch to the installed version, using:

    $ nvm use 0.10
    

    Also, you can create the .nvmrc file containing the version number, then switch to the specified version using the following command:

    $ nvm use
    

    To see the list of installed node.js versions, use:

    $ nvm ls
    

    To list the versions available to install:

    $ nvm ls-remote
    

    nvm-windows (Windows)

    nvm-windows is a node.js version management utility for Windows, ironically written in Go.

    It is not the same thing as nvm. However, the usage as a node.js version manager is very similar.

    To install nvm-windows, it is required to uninstall any existing versions of node.js and npm beforehand. Then, download and run the latest installer from releases.

    To upgrade nvm-windows, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations.

    nvm-windows runs in an Admin shell. You'll need to start Powershell or Command Prompt as Administrator to use nvm-windows.

    Before using, you may also need to enable nvm-windows with the following command:

    C:\> nvm on
    

    To download and install a specific node.js and npm version, use:

    C:\> nvm install 0.12
    

    Then, you can switch to the installed version, using:

    C:\> nvm use 0.12
    

    If you want to see the list of installed node.js versions, use:

    C:\> nvm list
    

    To list the versions available to install:

    C:\> nvm list available
    
    0 讨论(0)
提交回复
热议问题