1. Using homebrew install nvm:

    brew update
    brew install nvm
    source $(brew --prefix nvm)/nvm.sh
    

    Add the last command to the .profile, .bashrc or .zshrc file to not run it again on every terminal start. So for example to add it to the .profile run:

    echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profile
    

    If you have trouble with installing nvm using brew you can install it manually (see here)

  2. Using nvm install node or iojs (you can install any version you want):

    nvm install 0.10
    # or
    nvm install iojs-1.2.0
    
  3. npm is shipping with node (or iojs), so it will be available after installing node (or iojs). You may want to upgrade it to the latest version:

    $ npm install -g npm@latest
    

    UPD Previous version was npm update -g npm. Thanks to @Metallica for pointing to the correct way (see the comment below).

  4. Using npm install ionic:

    npm install -g ionic
    
  5. What about ngCordova: you can install it using npm or bower. I don't know what variant is more fit for you, it depends on the package manager you want to use for the client side. So I'll describe them both:

    1. Using npm: Go to your project folder and install ng-cordova in it:

      npm install --save ng-cordova
      
    2. Using bower: Install bower:

       npm install -g bower
      

      And then go to your project folder and install ngCordova in it:

       bower install --save ngCordova
      

PS

  1. Some commands may require superuser privilege
  2. Short variant of npm install some_module is npm i some_module
Answer from alexpods on Stack Overflow
Top answer
1 of 11
307
  1. Using homebrew install nvm:

    brew update
    brew install nvm
    source $(brew --prefix nvm)/nvm.sh
    

    Add the last command to the .profile, .bashrc or .zshrc file to not run it again on every terminal start. So for example to add it to the .profile run:

    echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profile
    

    If you have trouble with installing nvm using brew you can install it manually (see here)

  2. Using nvm install node or iojs (you can install any version you want):

    nvm install 0.10
    # or
    nvm install iojs-1.2.0
    
  3. npm is shipping with node (or iojs), so it will be available after installing node (or iojs). You may want to upgrade it to the latest version:

    $ npm install -g npm@latest
    

    UPD Previous version was npm update -g npm. Thanks to @Metallica for pointing to the correct way (see the comment below).

  4. Using npm install ionic:

    npm install -g ionic
    
  5. What about ngCordova: you can install it using npm or bower. I don't know what variant is more fit for you, it depends on the package manager you want to use for the client side. So I'll describe them both:

    1. Using npm: Go to your project folder and install ng-cordova in it:

      npm install --save ng-cordova
      
    2. Using bower: Install bower:

       npm install -g bower
      

      And then go to your project folder and install ngCordova in it:

       bower install --save ngCordova
      

PS

  1. Some commands may require superuser privilege
  2. Short variant of npm install some_module is npm i some_module
2 of 11
132

Use nvm to install Node.js, not Homebrew

In most of the answers, the recommended way to install nvm is to use Homebrew.

Don't do this.

On nvm's Github Readme is clearly says:

Homebrew installation is not supported. If you have issues with homebrew-installed nvm, please brew uninstall it, and install it using the instructions below, before filing an issue.

Use the following method instead

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

The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

And then use nvm to install node. For example to install latest LTS version do:

nvm install 16

Clean and hassle free. It will set this as your default Node.js version as well so you should be all set.

๐ŸŒ
Newline
newline.co โ€บ @Adele โ€บ how-to-install-nodejs-and-npm-on-macos--22782681
How to install Node.js and npm on macOS | newline
June 25, 2020 - In this post, we'll be looking at three different ways to install Node.js and its package manager, Node Package Manager, on macOS. We will discuss how to install Node.js using mac-native package installer, homebrew, a 3rd party installer, Node Version Manager and how to hop between different Node.js versions using Node Version Manager ยท
๐ŸŒ
Pinegrow Community
forum.pinegrow.com โ€บ general โ€บ random
What is the Best, better Way to Install Node.js, NPM on a mac? - Random - Pinegrow Community Forum
Hello! as it says above. Iโ€™m pretty sure this could either be ignored, or start a flame war. โ€ฆor Iโ€™ll be totally blown away by everyone agreeing on one way! But Macportsโ€ฆ https://www.macports.org/ Homebrewโ€ฆ โ€ฆ the stand alone Installer, made by the devs themselves?
Published ย  February 14, 2021
๐ŸŒ
The Surly Dev
surly.dev โ€บ articles โ€บ how-to-setup-node-on-mac
How to Setup Node on Mac Without Homebrew
This post shows you how to setup Node.js on a Mac without using Homebrew. ... A specific version of Node.js. In this case, the latest LTS (Long Term Support) version. ... nvm (Node Version Manager) is a version manager for Node.js, designed to manage multiple versions of Node.js on a single machine. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash
๐ŸŒ
Medium
medium.com โ€บ @littlecodingthings โ€บ how-to-install-npm-on-macos-039b77e37244
How to Install npm on MacOS. Installing Node.js and NPM (Nodeโ€ฆ | by Little Coding Things | Medium
1 week ago - How to Install npm on MacOS Installing Node.js and npm (Node Package Manager) on your Mac is super simple. With these tools, you can manage Javascript packages, create powerful web applications, and โ€ฆ
๐ŸŒ
Treehouse
treehouse.github.io โ€บ installation-guides โ€บ mac โ€บ node-mac.html
Installing Node.jsยฎ and NPM on Mac
NPM is a โ€œpackage managerโ€ that makes installing Node โ€œpackagesโ€ fast and easy. A package, also called a module, is just a code library that extends Node by adding useful features. For example, the โ€œrequestโ€ module simplifies the process of making HTTP requests so you can easily get web resources from other sites. ... Although there is Mac installer program on the Node website, we recommend using Homebrew to install and update Node.
๐ŸŒ
pawelgrzybek
pawelgrzybek.com โ€บ install-nodejs-installer-vs-homebrew-vs-nvm
Install Node.js โ€” installer vs. Homebrew vs. NVM | pawelgrzybek.com
I published โ€œFix privileges and never again use sudo with npmโ€ with some solutions for this issue, but you better check โ€œResolving EACCES permissions errors when installing packages globallyโ€ on official documentation or follow this article. โ€œHomebrew โ€” the best friend of the macOS ...
Find elsewhere
๐ŸŒ
GitHub
gist.github.com โ€บ rcugut โ€บ c7abd2a425bb65da3c61d8341cd4b02d
Install node & npm on Mac OS X with Homebrew ยท GitHub
# run the following commands # ... latest 'node' # - if you don't use `yarn` (yarnpkg.com), prefer LTS 'node@6' brew install node --without-npm # install yarn (see yarnpkg.com for more info) brew install yarn # follow up with: ...
๐ŸŒ
Reddit
reddit.com โ€บ r/webdev โ€บ nvm or homebrew for node install
r/webdev on Reddit: Nvm or homebrew for Node install
April 12, 2023 -

I come across this decision every time I get a new Mac laptop/computer.

I like nvm, node version manager, because it allows me to install multiple versions of node/npm in case I need to switch within different versions.

Does homebrew offer the same? Are there other install recommendations for Mac?

The need to switch node versions does come up when asked to work on another project that is โ€œstuckโ€ on an older version of node due to outdated packages that no one wants to maintain but is still used in the project.

April 12, 2023 Update Thanks for all the great recommendations and insight. I decided to use fnm for my own preference at this time, but all alternatives seem great in their own way. Here is a great article from Honeybadger comparing many node environment managers: https://www.honeybadger.io/blog/node-environment-managers

๐ŸŒ
Reddit
reddit.com โ€บ r/node โ€บ have node installed on mac, but not npm, suggestions? is there a way to install npm separately?
r/node on Reddit: have node installed on mac, but not npm, suggestions? is there a way to install npm separately?
June 25, 2019 -

I installed node in the past with the help of someone irrc, but npm is not installed when I checked:

Mac-Users-Apple-Computer:~ z$ npm -v
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module '../lib/utils/unsupported.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:153:3)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

I guess I wanted to try a clean install of node.js with npm, but when I tried to remove node, I got this, a yarn dependency, something I also had someone help install at some point for something(can tell, I'm a newbie to this):

Mac-Users-Apple-Computer:~ z$ brew uninstall node
Error: Refusing to uninstall /usr/local/Cellar/node/11.11.0
because it is required by yarn, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies node

Should I override / remove node and do an install from scratch? Or can I install npm separately(don't know that that would be advised). it seems brew install node should install node and npm based on a reference link further down below, I just don't see npm on my system right now and don't recall how i had node installed the first time.

here are some references I was looking at:

https://treehouse.github.io/installation-guides/mac/node-mac.html

https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x

๐ŸŒ
GitHub
gist.github.com โ€บ DanHerbert โ€บ 9520689
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew ยท GitHub
Homebrew maintainers have fixed things and the options mentioned don't exist and won't work. I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-Homebrew-and-NPM-macOS-X
What is the difference between Homebrew and NPM (macOS X)? - Quora
Answer: Thanks for your A2A P. Withayasakpunt! Homebrew is a Unix-like package manager that should have been included in the original version of MAC OS X but was not. NPM is a set of web dev libraries for Node, JS, and the like within Homebrew. Now one can install NPM without Homebrew but then y...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ can't install npm on mac
r/learnjavascript on Reddit: can't install npm on mac
September 14, 2020 -

Hi everyone,

I'm building a website where I would like to apply this effect. So I read that I need to install npm in order to download its dependencies. The thing is that when I execute the command npm install I get this error: -bash: npm: command not found I searched for this error trying to figuring out what's wrong but I could't find a solution. I'm currently using Mac High Sierra operating system.

Can you help me understand how to install npm correctly?

thanks

๐ŸŒ
Reddit
reddit.com โ€บ r/node โ€บ if i'm going to use homebrew, does that mean i should just install everything with homebrew from the very beginning?
r/node on Reddit: If I'm going to use Homebrew, does that mean I should just install EVERYTHING with Homebrew from the very beginning?
December 1, 2020 -

I had a major problem with Homebrew in the past and I know it had something to do with symlinks and Node. I'm pretty sure I stumbled through completely uninstalling Node and completely uninstalling Homebrew and then reinstalling Node and NPM and everything all over again...but I don't want to go through that crap again.

Most people seem to recommend Homebrew and say "everyone is doing it" like I'm a moron if I don't want to use it, so I figured I will try to get with the program and learn how to use it. Should I just install Node with Homebrew from the get-go if I'm going to be using Homebrew anyway? Thanks.

๐ŸŒ
Quora
quora.com โ€บ What-is-the-best-way-to-install-Node-JS-and-npm-on-OS-X
What is the best way to install Node JS and npm on OS X? - Quora
Answer (1 of 2): I somehow don't like installing through the .pkg files given on Node's website. Well, I'm personally against installing any .pkg files at all if I can help it, so if you ask me my suggestions will be either: 1. Install via Homebrew. This options gives you version upgrades for ea...
๐ŸŒ
Positiwise
positiwise.com โ€บ home โ€บ install npm on mac | easiest way possible
Install npm on Mac | Easiest Way Possible - Positiwise
July 4, 2024 - Install npm on Mac with this easy step-by-step guide. Follow our simple instructions to set up Node.js and npm on your macOS system.