macOS – Best Way to Install Node.js on OS X

homebrewinstallmacos

I currently have installed node and npm with the installer provided from their website. Although I have homebrew installed as well, and running brew doctor seems to complain about some files installed by the node js installer at /usr/local/include/.

Is installing node through homebrew a better way (e.g. easier to manage, less errors and warnings, etc.)?

Best Answer

I find the best way to install Node.js is to use nvm, which allows you to install and manage multiple versions of Node.

I use Homebrew for pretty much everything else, but Node is easier to use through nvm, since it doesn't use global folders - everything is in your home directory, and you can easily switch between Node versions.

To install (check the website for the latest version):

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

There are some specific notes about OS X on the web site, please make sure to read through those, e.g. regarding the use of the ~/.bash_profile file.

After that, the nvm function will allow you to specify which version of node to install and use. In the simplest case, you run

nvm install node

which will install the stable version of Node.js.