Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

node.js - 如何更新Node.js?(How do I update Node.js?)

I did the following to update my npm:

(我做了以下更新我的npm:)

npm update npm -g

But I have no idea how to update Node.js.

(但是我不知道如何更新Node.js。)

Any suggestions?

(有什么建议么?)

(I'm using Node.js 0.4.1 and want to update to Node.js 0.6.1.)

((我正在使用Node.js 0.4.1,并想更新到Node.js 0.6.1。))

  ask by alexchenco translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(我按照以下说明从Mac上的Node.js版本0.10.6升级到0.10.21。)

  1. Clear NPM's cache:

    (清除NPM的缓存:)

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

    (安装一个名为“ n”的小助手)

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

    (安装最新的稳定Node.js版本)

     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):

(更新(2017年6月):)

This four years old post still receives up-votes so I'm guessing it still works for many people.

(这个已有4年历史的帖子仍然获得投票支持,所以我猜它仍然对很多人有用。)

However, Mr. Walsh himself recommended to update Node.js just using nvm instead.

(但是,沃尔什先生本人建议仅使用nvm更新Node.js。)

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

(因此,这是您今天可能想要做的:)

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

(找出您正在使用哪个版本的Node.js:)

node --version

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

(找出您可能已经安装了哪个版本的Node.js,以及当前正在使用的哪个版本:)

nvm ls

List all versions of Node.js available for installation:

(列出所有可用于安装的Node.js版本:)

nvm ls-remote

Apparently for Windows the command would be rather like this:

(显然,对于Windows,该命令将如下所示:)

nvm ls available

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

(假设您选择Node.js v8.1.0进行安装,则键入以下内容以安装该版本:)

nvm install 8.1.0

You are then free to choose between installed versions of Node.js.

(然后,您可以自由选择安装的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:

(因此,如果您需要使用v4.2.0之类的旧版本,则可以将其设置为活动版本,如下所示:)

nvm use 4.2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...