在 Mac OS 上将 Node.js 升级到最新版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11284634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upgrade Node.js to the latest version on Mac OS
提问by afterglowlee
Currently I am using Node.js v0.6.16 on Mac OS X 10.7.4. Now I want to upgrade it to the latest Node.js v0.8.1. But after downloading and installing the latest package file from nodejs.org, I found that system is still using v0.6.16 instead of v0.8.1 when I typed "node -v" in a terminal. Is there any step that I have missed? Or, should I thoroughly uninstall the old version before installing the latest one?
目前我在 Mac OS X 10.7.4 上使用 Node.js v0.6.16。现在我想将它升级到最新的 Node.js v0.8.1。但是从nodejs.org下载并安装最新的包文件后,我发现当我在终端中输入“node -v”时,系统仍在使用v0.6.16而不是v0.8.1。有没有我遗漏的步骤?或者,我应该在安装最新版本之前彻底卸载旧版本吗?
BTW, I know that nvm can help to manage the nodejs package
顺便说一句,我知道 nvm 可以帮助管理 nodejs 包
https://github.com/creationix/nvm/
https://github.com/creationix/nvm/
Is there any way to upgrade the Node.js without using it?
有没有办法在不使用 Node.js 的情况下升级它?
I have googled this problem, but it seems to me that there is no very clear answer to this question for the latest Node.js.
我已经在 google 上搜索了这个问题,但在我看来,对于最新的 Node.js,这个问题没有非常明确的答案。
回答by Johan Dettmar
Here's how I successfully upgraded from v0.8.18to v0.10.20without any other requirementslike brew etc, (type these commands in the terminal):
这是我v0.8.18在v0.10.20没有任何其他要求(如 brew 等)的情况下成功升级到 的方法(在终端中输入这些命令):
sudo npm cache clean -f(force) clear you npm cachesudo npm install -g ninstall n(this might take a while)sudo n stableupgrade to the current stable version
sudo npm cache clean -f(强制)清除你的 npm 缓存sudo npm install -g n安装n(这可能需要一段时间)sudo n stable升级到当前的稳定版本
Note that sudomight prompt your password.
请注意,这sudo可能会提示您输入密码。
Additional note regarding step 3: stablecan be exchanged for latest, lts(long term support) or any specific version number such as 0.10.20.
关于第 3 步的附加说明:stable可以交换为latest, lts(长期支持)或任何特定版本号,例如0.10.20.
If the version number doesn't show up when typing node -v, you might have to reboot.
如果键入时未显示版本号node -v,则可能需要重新启动。
These instructions are found here as well: davidwalsh.name/upgrade-nodejs
More info about the npackage found here: npmjs.com/package/n
More info about Node.js' release schedule: github.com/nodejs/Release
这些说明也可在此处找到:davidwalsh.name/upgrade-nodejs
有关n包的更多信息,请参阅:npmjs.com/package/n
有关 Node.js 发布时间表的更多信息:github.com/nodejs/Release
回答by wprl
If you initially installed Node.jswith Homebrew, run:
如果您最初使用Homebrew安装了Node.js,请运行:
brew update
brew upgrade node
npm install -g npm
Or as a one-liner:
或者作为单线:
brew update && brew upgrade node && npm install -g npm
A convenient way to change versions is to use nvm:
更改版本的一种便捷方法是使用nvm:
brew install nvm
To install the latest version of Node.js with nvm:
要使用 nvm 安装最新版本的 Node.js:
nvm install node
If you installed via a package, then download the latest version from nodejs.org. See Installing Node.js and updating npm.
如果您通过软件包安装,请从nodejs.org下载最新版本。请参阅安装 Node.js 和更新 npm。
回答by Kennedy Nyaga
Because this seems to be at the top of Google when searching for how to upgrade nodejs on mac I will offer my tip for anyone coming along in the future despite its age.
因为在搜索如何在 mac 上升级 nodejs 时,这似乎是谷歌的顶部,我会为将来出现的任何人提供我的提示,尽管它年龄很大。
Upgrading via NPM
You can use the method described by @Mathias above or choose the following simpler method via the terminal.
通过 NPM 升级
您可以使用上面@Mathias 描述的方法或通过终端选择以下更简单的方法。
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
After which you may opt to confirm the upgrade
之后您可以选择确认升级
node -v
Your nodejs should have upgraded to the latest version. If you wish to upgrade to a specific one say v0.8.19 then instead of
您的 nodejs 应该已升级到最新版本。如果您希望升级到特定版本,请说 v0.8.19,而不是
sudo n stable
use
用
sudo n 0.8.19
EDITAvoid using sudo unless you need to. Refer to comment by Steve in the comments
编辑除非需要,否则避免使用 sudo。参考 Steve 在评论中的评论
回答by Spoeken
Go to http://nodejs.organd download and run the installer. It works now - for me at least.
转到http://nodejs.org并下载并运行安装程序。它现在有效 - 至少对我来说。
回答by fijiaaron
You could install nvmand have multiple versions of Node.js installed.
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
and then run:
然后运行:
nvm install 0.8.22 #(or whatever version of Node.js you want)
you can see what versions you have installed with :
你可以看到你安装了哪些版本:
nvm list
and you can change between versions with:
您可以通过以下方式在版本之间进行更改:
nvm use 0.8.22
The great thing about using NVM is that you can test different versions alongside one another. If different apps require different versions of Node.js, you can run them both.
使用 NVM 的好处在于您可以同时测试不同的版本。如果不同的应用程序需要不同版本的 Node.js,您可以同时运行它们。
回答by Shaikh Shahid
I use Node version manager (called n) for it.
我使用 Node 版本管理器(称为 n)。
npm install -g n
then
然后
n latest
OR
或者
n stable
回答by Tarandeep Singh
Simply go to node JS Website and install the latest version.
只需转到节点 JS 网站并安装最新版本。
Do install latest version instead of the recommended stable version. It will give you freedom to use latest ES6 Features on node.
请安装最新版本而不是推荐的稳定版本。它将让您自由地在节点上使用最新的 ES6 功能。
Can be Found here Node JS.
可以在这里找到Node JS。
also to update npm, you will have to use this command.
还要更新npm,您将不得不使用此命令。
sudo npm i -g npm@latest
sudo npm i -g npm@latest
All your projects will work fine.
你所有的项目都会正常工作。
Other option for mac :: brew update && brew install node && npm -g npm
mac 的其他选择 :: brew update && brew install node && npm -g npm
回答by Nick Woodhams
On macOS the homebrew recommended way is to run
在 macOS 上,自制软件推荐的方式是运行
brew install node
npm install -g npm@latest


回答by Rohit Kale
I am able to upgrade the node using following command
我可以使用以下命令升级节点
nvm install node --reinstall-packages-from=node
回答by Jannomeister
sadly, ndoesn't worked for me. I use node version manager or nvmand it works like a charm. heres the link on how to install nvm: https://github.com/creationix/nvm#installation
可悲的是,n对我不起作用。我使用node version manager or nvm它,它就像一个魅力。这是关于如何安装的链接nvm:https: //github.com/creationix/nvm#installation
nvm i 8.11.2upgrade to latest LTSnvm use 8.11.2use itnode -vcheck your latest version
nvm i 8.11.2升级到最新的 LTSnvm use 8.11.2用它node -v检查您的最新版本

