2012-04-09 16:02

将 Node.js 升级到最新版本


So, I have Node.js installed and now when I tried to install Mongoosejs I got an error telling me that I don't have the needed version of Node.js (I have v0.4.11 and v0.4.12 is needed).

How can I upgrade to this version? I suppose I just could install it again with the latest version, but I don't want to do it before I'm sure that my project folders in the folder "node" won't be deleted.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • csdnceshi62 csdnceshi62 9年前


    The module n makes version-management easy:

    sudo npm install n -g

    For the latest stable version:

    sudo n stable

    For the latest version:

    sudo n latest


    just reinstall node from the .msi in Windows from the node website.

    点赞 25 评论 复制链接分享
  • csdnceshi73 喵-见缝插针 9年前

    2018 Solution Without sudo!

    The Current/Stable "LTS" version of node is 10.13.0 (2018-11-01) see: nodejs.org for latest.

    Step 1 - Get NVM (Node Version Manger)

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

    If you're curious about the installation command read the source code
    ... its been reviewed by several security experts

    Step 2 - Install the version of node.js you need

    Once you've got NVM you can install a specific version of Node.js using the nvm command:

    nvm install v10.13.0

    Note: you may need to close & re-open your terminal window for nvm command to be available.

    You should expect to see something like this in your terminal:

    Now using node v10.13.0

    Step 3 - Enjoy the rest of your day!

    Yes, it's that easy and didn't require sudo!
    Now please Upvote this (so others can avoid sudo-installing things!)
    and have a lovely day writing node.js code!

    Microsoft Windows User? See: https://github.com/coreybutler/nvm-windows


    Review of the node mailing list indicates that using NVM (Node Version Manager) is the preferred way to manage your nodejs versioning/upgrading. see: github.com/creationix/nvm

    NVM by Tim Caswell (& friends) is "better" than N from visionmedia (TJ Holowaychuk) github.com/visionmedia/n because the verbose commands mean is much easier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittens by not requiring sudo and is used by the team at liftsecurity.io the node.js security experts!

    Also worth noting: NVM has almost three times as many GitHub Stars as N (22896 vs 8040). That's usually - but not always - a sign of a better module... feel free to correct if you have evidence of otherwise ...

    P.S. this may be a dupe of How can I uninstall or upgrade my old node.js version?

    点赞 26 评论 复制链接分享
  • csdnceshi79 python小菜 4年前

    All platforms (Windows, Mac & Linux)

    Just go to nodejs.org and download the latest installer. It couldn't be any simpler honestly, and without involvement of any third-party stuff. It only takes a minute and does not require you to restart anything or clean out caches, etc.

    I've done it via npm a few times before and have run into a few issues. Like for example with the n-package not using the latest stable release.

    点赞 10 评论 复制链接分享
  • csdnceshi51 旧行李 3年前

    I used https://chocolatey.org/install

    1. install chocolatey refering this https://chocolatey.org/install
    2. run in cmd

    cup nodejs

    That's all. NodeJs now updated to latest version

    点赞 9 评论 复制链接分享
  • csdnceshi78 程序go 7年前

    Upgrading node.js to the latest version on Windows

    1. Install chocolatey if you haven't already: Installing Chocolatey

    2. From the command prompt, type

      cup nodejs

    (which is equivalent to typing choco upgrade nodejs -- assumes you already have node installed)

    NOTE: You may need to run cinst nodejs.install for chocolatey to register your existing installation. (thanks for the comment, @mikecheel)

    Installing node.js on Windows

    If you have never installed node, you can use chocolatey to do that as well. Install chocolatey (see step 1 above). Then from a command prompt, type:

    cinst nodejs.install

    Chocolatey Gallery Node JS (Install)

    Installing a specific version of node on Windows with chocolatey

    cinst nodejs.install -Version 0.10.26

    点赞 8 评论 复制链接分享
  • csdnceshi66 必承其重 | 欲带皇冠 4年前

    Following Upgrading Node.js to latest version

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

    For Upgrading Node.js to latest version

    sudo n latest

    If you need to do Undo then follow command

    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

    This method of upgrading node is now unstable and should not be used. The best way to manage Node.js versions is to use NVM: Node Version Management.!


    You can read the installation steps on the nvm [GitHub page][1]. There are only two easy steps for installation and configuration. Using nvm

    If you work with a lot of different Node.js utilities, you know that sometimes you need to quickly switch to other versions of Node.js without hosing your entire machine. That's where you can use nvm to download, install, and use different versions of Node.js:

    nvm install 4.0

    At any given time you can switch to another with use:

    nvm use 0.12
    点赞 8 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 4年前

    There is good explanation for linux users how to update node version step by step. P.S type instead of sudo n stable sudo n latest for receive latest node version.

    If you receive following error

    Error: Module version mismatch. Expected 48, got 46.

    You have just rebuilt npm by the following command npm rebuild it should fix the problem.

    点赞 8 评论 复制链接分享
  • csdnceshi51 旧行李 8年前

    via npm:

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

    and also you can specify a desired version:

    # n 0.8.21


    点赞 7 评论 复制链接分享
  • csdnceshi68 local-host 3年前

    sudo npm install n -g sudo n 0.12.2


    sudo npm install -g n sudo n latest


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

    These work well. But for UX term terminal node -v did not show latest version so I have closed and reopened new terminal. I found v10.1.0, output of node-v after installation by sudo n latest

    点赞 6 评论 复制链接分享
  • csdnceshi77 狐狸.fox 3年前

    just try this on your terminal :

    nvm install node --reinstall-packages-from=node

    it should do the trick.

    later, run node --version to check the version that you have.

    点赞 4 评论 复制链接分享
  • weixin_41568127 ?yb? 8年前

    my 2c:

    I tried both with n and with nvm on Linux Ubuntu 12.04 LTS, in order to update node from v0.8.25 to v0.10.22.

    The first one was successfully completed, but the command 'which node' resulted in the old v0.8.25.
    The second one was successfully completed and the same command resulted in v.0.10.22.

    点赞 4 评论 复制链接分享
  • weixin_41568127 ?yb? 4年前

    Install npm =>

    sudo apt-get install npm

    Install n =>

    sudo npm install n -g

    latest version of node =>

    sudo n latest 

    So latest version will be downloaded and installed

    Specific version of node you can

    List available node versions =>

    n ls

    Install a specific version =>

    sudo n 4.5.0
    点赞 4 评论 复制链接分享
  • csdnceshi61 derek5. 4年前

    Using brew and nvm on Mac OSX:

    If you're not using nvm, first uninstall nodejs. Then install Homebrew if not already installed. Then install nvm and node:

    brew install nvm
    nvm ls-remote    # find the version you want
    nvm install v7.10.0
    nvm alias default v7.10.0    # set default node version on a shell

    You can now easily switch node versions when needed.

    Bonus: If you see a "tar: invalid option" error when using nvm, brew install gnu-tar and follow the instructions brew gives you to set your PATH.

    点赞 3 评论 复制链接分享
  • csdnceshi69 YaoRaoLov 4年前

    For Windows users, simply go to the node.js (nodejs.org) website and download the latest version (8.6.0 as of 09/29/2017). Follow the steps from the auto install window and you're good to go. I just did it and when I checked my latest version in webstorm, it was already there.

    点赞 3 评论 复制链接分享
  • csdnceshi68 local-host 5年前

    You don't need to worry about an upgrading process.

    You can just install the newest version using the official documentation as if you didn't have it installed and it will work like a charm. > https://nodejs.org/en/download/package-manager/ ;)

    点赞 2 评论 复制链接分享
  • csdnceshi59 ℙℕℤℝ 4年前

    I had node version v7.10.0 in Ubuntu

    Used below commands to upgrade

    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    sudo apt-get install -y nodejs

    Now its upgraded to v8.2.1


    sudo apt-get install make
    sudo curl -L https://git.io/n-install | bash
    . /home/$USER/.bashrc
    # Below command should get the latest version of node
    node --version
    # Install specific version of node
    n 8.2
    # Check for the Node Version installed
    node --version
    点赞 2 评论 复制链接分享
  • csdnceshi73 喵-见缝插针 5年前
    brew upgrade node

    will upgrade to the latest version of the node

    点赞 2 评论 复制链接分享
  • csdnceshi74 7*4 7年前

    On Windows download latest "Windows Installer (.msi)" from https://nodejs.org/download/release/latest/ and install same directory , thats all...

    After complete the installation above, the NodeJS and NPM will be upgraded to the latest one and then you can cleanup the package as normal as:

    npm cache clean
    npm update -g


    You can always check the version with following command:

    C:\node -v
    C:\npm -version
    点赞 2 评论 复制链接分享
  • csdnceshi63 elliott.david 4年前

    Re-install the latest version of nodejs by downloading the latest .msi version from nodejs website here, https://nodejs.org/en/download/

    It worked for me in my windows machine.

    点赞 1 评论 复制链接分享
  • weixin_41568134 MAO-EYE 5年前

    After install nvm as @nelsonic describes, this is the easiest way to keep it upgraded:

    "node" is a shortcut to the last version, so you can install the last version with:

    nvm install node

    And to always use the "node" version:

    nvm alias default node

    Finally to upgrade your node version and keep the installed packages:

    nvm install node --reinstall-packages-from=node
    点赞 评论 复制链接分享
  • csdnceshi74 7*4 5年前

    For Windows

    I had the same problem, I tried to reinstall and didn't worked for me.

    Remove "C:\Program Files(x86)\nodejs" from your system enviorment PATH and thats it!

    点赞 评论 复制链接分享
  • weixin_41568183 零零乙 4年前

    Just bundling node and npm updates to latest version into a single command for my ~/.bash_profile:

      sudo n latest;
      sudo npm install -g npm;
      node --version;

    This assumes you've already installed "n" from Eldar Djafarov's answer. After saving this to your Bash profile, re-open the terminal and just type update-node and enter your sudo password:

    λ update-node
    /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
    /usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
    + npm@5.3.0
    updated 1 package in 7.232s
    点赞 评论 复制链接分享
  • csdnceshi53 Lotus@ 3年前

    只需运行命令行 npm install -g npm 或者sudo npm install -g npm为Mac用户更新 而已.

    点赞 评论 复制链接分享
  • weixin_41568174 from.. 3年前

    Windows 10

    Open CMD in folder C:\Program Files\nodejs\node_modules and type npm i npm

    点赞 评论 复制链接分享
  • weixin_41568134 MAO-EYE 5年前

    If you are looking in linux..

    npm update will not work mostly am not sure reason but following steps will help you to resolve issue...

    Terminal process to upgrade node 4.x to 6.x.

     $ node -v

    Check node path

    $ which node

    Download latest(6.x) node files from [Download][1]

    [1]: https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz and unzip files keep in /opt/node-v6.9.2-linux-x64/.

    Now unlink current node and link with latest as following

    $ unlink /usr/bin/node
    $ ln -s /opt/node-v6.9.2-linux-x64/bin/node node
    $ node -v
    $ v6.9.2
    点赞 评论 复制链接分享
  • csdnceshi58 Didn"t forge 4年前

    If Node install script doesn't work for you (it didn't for me), here's the solution to update Node Js in Debian Jessie, taken from the reply from Thomas Ward at askubuntu.com (Thanks, buddy!).

    1.- Create a new file: /etc/apt/sources.list.d/nodesource.list

    You'll need to create this file with sudo, but when you create the file, put this inside it:

    deb https://deb.nodesource.com/node_9.x jessie main
    deb-src https://deb.nodesource.com/node_9.x jessie main

    Then, save the file. (replace node_9.x with the desired version)

    2.- Download the GPG Signing Key from Nodesource for the repository. Otherwise, you may get NO_PUBKEY errors with apt-get update:

    curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -

    3.- Manually run sudo apt-get update.

    This refreshes the data from the nodesource repo so apt knows a newer version exists.

    If you get a NO_PUBKEY GPG error, then go back to Step 2

    4.- Check apt-cache policy nodejs output.

    This is not done by the script, but you want to make sure you see an entry that says something like this in the output:

    Version table:
     *** 9.2.0-1nodesource1 0
            500 https://deb.nodesource.com/node_9.x/ jessie/main amd64 Packages
            100 /var/lib/dpkg/status
         0.10.29~dfsg-2 0
            500 http://ftp.debian.org/debian/ jessie/main amd64 Packages

    If you do not see entries like this, and only see 0.10.29, start over. Otherwise, proceed.

    5.- Install the nodejs binary. Now that you have confirmed 9.x is available on your system, you can install it: sudo apt-get install nodejs

    nodejs -v should now show v9.2 or similar on output (as long as it starts with v9. you're on version 9 then).

    点赞 评论 复制链接分享