How do I update Node.js?

2019-01-01 02:53发布

I did the following to update my npm:

npm update npm -g

But I have no idea how to update Node.js. Any suggestions? (I'm using Node.js 0.4.1 and want to update to Node.js 0.6.1.)

30条回答
墨雨无痕
2楼-- · 2019-01-01 03:18

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.

查看更多
琉璃瓶的回忆
3楼-- · 2019-01-01 03:19

On Windows you can use Chocolatey to install and update Node.js (and lots of other packages).

Install Node

cinst nodejs.install

Update Node

cup nodejs.install

Note: You will need to install Chocolatey before you can use cinst and cup.

查看更多
牵手、夕阳
4楼-- · 2019-01-01 03:21

To control your version of Node.js, you can try n. I found it very straightforward and useful.

n is a Node.js binary management, no subshells, no profile setup, no convoluted API, just simple.

npm install -g n

n 0.6.19 will install Node.js v0.6.19.

查看更多
零度萤火
5楼-- · 2019-01-01 03:21

For Ubuntu:

sudo apt-get install -y curl
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs

Source: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

查看更多
千与千寻千般痛.
6楼-- · 2019-01-01 03:22

I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac.

  1. Clear NPM's cache:

    sudo npm cache clean -f
    
  2. Install a little helper called 'n'

    sudo npm install -g n
    
  3. Install latest stable Node.js version

    sudo n stable
    

Alternatively pick a specific version and install like this:

sudo n 0.8.20

For production environments you might want to pay attention to version numbering and be picky about odd/even numbers.

Credits


Update (June 2017):

This four years old post still receives up-votes so I'm guessing it still works for many people. However, Mr. Walsh himself recommended to update Node.js just using nvm instead.

So here's what you might want to do today:

Find out which version of Node.js you are using:

node --version

Find out which versions of Node.js you may have installed and which one of those you're currently using:

nvm ls

List all versions of Node.js available for installation:

nvm ls-remote

Apparently for Windows the command would be rather like this:

nvm ls available

Assuming you would pick Node.js v8.1.0 for installation you'd type the following to install that version:

nvm install 8.1.0

You are then free to choose between installed versions of Node.js. So if you would need to use an older version like v4.2.0 you would set it as the active version like this:

nvm use 4.2
查看更多
临风纵饮
7楼-- · 2019-01-01 03:24

As some of you already said, the easiest way is to update Node.js through the Node.js package manager, npm. If you are a Linux (Debian-based in my case) user I would suggest to add these lines to your .bashrc file (in home directory):

function nodejsupdate() {
    ARGC=$#
    version=latest
    if [ $ARGC != 0 ]; then
        version=$1
    fi
    sudo npm cache clean -f
    sudo npm install -g n
    sudo n $version
}

Restart your terminal after saving and write nodejsupdate to update to the latest version of Node.js or nodejsupdate v6.0.0 (for example) to update to a specific version of Node.js.

BONUS: Update npm (add these lines to .bashrc)

function npmupdate() {
    sudo npm i npm -g
}

After restarting the terminal write npmupdate to update your node package manager to the latest version.

Now you can update Node.js and npm through your terminal (easier).

查看更多
登录 后发表回答