將Node.js升級到Mac OS上的最新版本

本文翻譯自:Upgrade Node.js to the latest version on Mac OS

Currently I am using Node.js v0.6.16 on Mac OS X 10.7.4. 目前我在Mac OS X 10.7.4上使用Node.js v0.6.16。 Now I want to upgrade it to the latest Node.js v0.8.1. 現在我想將它升級到最新的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. 但是從nodejs.org下載並安裝最新的軟件包文件後,我發現當我在終端中輸入“node -v”時,系統仍在使用v0.6.16而不是v0.8.1。 Is there any step that I have missed? 有沒有我錯過的一步? Or, should I thoroughly uninstall the old version before installing the latest one? 或者,我應該在安裝最新版本之前徹底卸載舊版本嗎?

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. 我已經搜索了這個問題,但在我看來,對於最新的Node.js,這個問題沒有非常明確的答案。


#1樓

參考:https://stackoom.com/question/lLeE/將Node-js升級到Mac-OS上的最新版本


#2樓

If you initially installed Node.js with Homebrew , run: 如果您最初使用Homebrew安裝Node.js ,請運行:

brew update
brew upgrade node
npm update -g npm

Or as a one-liner: 或者作爲一個單行:

brew update && brew upgrade node && npm update -g npm

Note: If you have npm --version < 2.7.1, you should replace update (above) with install . 注意:如果你有npm --version <2.7.1,你應該用install替換update (上面)。


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 . 如果您通過軟件包安裝,則從nodejs.org下載最新版本。 See Installing Node.js and updating npm . 請參閱安裝Node.js並更新npm


#3樓

Go to http://nodejs.org and download and run the installer. 轉到http://nodejs.org並下載並運行安裝程序。 It works now - for me at least. 它現在起作用 - 至少對我來說。


#4樓

You could install nvm and have multiple versions of Node.js installed. 您可以安裝nvm並安裝多個版本的Node.js.

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. 使用NVM的好處在於您可以並排測試不同的版本。 If different apps require different versions of Node.js, you can run them both. 如果不同的應用程序需要不同版本的Node.js,您可以同時運行它們。


#5樓

Here's how I successfully upgraded from v0.8.18 to v0.10.20 without any other requirements like brew etc, (type these commands in the terminal): 以下是我成功地從v0.8.18升級到v0.10.20 而沒有任何其他要求,如brew等,(在終端中輸入這些命令):

  1. sudo npm cache clean -f (force) clear you npm cache sudo npm cache clean -f (強制)清除npm緩存
  2. sudo npm install -gn install n (this might take a while) sudo npm install -gn install n (這可能需要一段時間)
  3. sudo n stable upgrade to the current stable version sudo n stable升級到目前的穩定版本

Note that sudo might prompt your password. 請注意, sudo可能會提示您輸入密碼。

Additional note regarding step 3: stable can be exchanged for latest , lts (long term support) or any specific version number such as 0.10.20 . 關於步驟3的附加說明: stable可以換成latestlts (長期支持)或任何特定版本號,例如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 這些說明也可以在這裏找到: davidwalsh.name/upgrade-nodejs
More info about the n package found here: npmjs.com/package/n 有關n包的更多信息,請訪問: npmjs.com/package/n
More info about Node.js' release schedule: github.com/nodejs/Release 有關Node.js'發佈計劃的更多信息: github.com/nodejs/Release


#6樓

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 通過NPM升級
You can use the method described by @Mathias above or choose the following simpler method via the terminal. 您可以使用上面@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. 您的nodejs應該已升級到最新版本。 If you wish to upgrade to a specific one say v0.8.19 then instead of 如果你想升級到特定的一個說v0.8.19然後而不是

sudo n stable

use 使用

sudo n 0.8.19

EDIT Avoid using sudo unless you need to. 編輯除非您需要,否則請避免使用sudo。 Refer to comment by Steve in the comments 請參閱評論中Steve的評論

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章