Using
homebrewinstallnvm:brew update brew install nvm source $(brew --prefix nvm)/nvm.shAdd the last command to the
.profile,.bashrcor.zshrcfile to not run it again on every terminal start. So for example to add it to the.profilerun:echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profileIf you have trouble with installing
nvmusingbrewyou can install it manually (see here)Using
nvminstallnodeoriojs(you can install any version you want):nvm install 0.10 # or nvm install iojs-1.2.0npmis shipping withnode(oriojs), so it will be available after installingnode(oriojs). You may want to upgrade it to the latest version:$ npm install -g npm@latestUPD Previous version was
. Thanks to @Metallica for pointing to the correct way (see the comment below).npm update -g npmUsing
npminstallionic:npm install -g ionicWhat about
ngCordova: you can install it usingnpmorbower. 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:Using
npm: Go to your project folder and installng-cordovain it:npm install --save ng-cordovaUsing
bower: Install bower:npm install -g bowerAnd then go to your project folder and install
ngCordovain it:bower install --save ngCordova
PS
- Some commands may require superuser privilege
- Short variant of
npm install some_moduleisnpm i some_module
Using
homebrewinstallnvm:brew update brew install nvm source $(brew --prefix nvm)/nvm.shAdd the last command to the
.profile,.bashrcor.zshrcfile to not run it again on every terminal start. So for example to add it to the.profilerun:echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profileIf you have trouble with installing
nvmusingbrewyou can install it manually (see here)Using
nvminstallnodeoriojs(you can install any version you want):nvm install 0.10 # or nvm install iojs-1.2.0npmis shipping withnode(oriojs), so it will be available after installingnode(oriojs). You may want to upgrade it to the latest version:$ npm install -g npm@latestUPD Previous version was
. Thanks to @Metallica for pointing to the correct way (see the comment below).npm update -g npmUsing
npminstallionic:npm install -g ionicWhat about
ngCordova: you can install it usingnpmorbower. 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:Using
npm: Go to your project folder and installng-cordovain it:npm install --save ng-cordovaUsing
bower: Install bower:npm install -g bowerAnd then go to your project folder and install
ngCordovain it:bower install --save ngCordova
PS
- Some commands may require superuser privilege
- Short variant of
npm install some_moduleisnpm i some_module
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, pleasebrew uninstallit, 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.
Videos
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
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
It seems that the symlink of the old npm version still exists.
- Install the npm version you want
npm install -g [email protected]
- Remove the sym link in /usr/local/bin/
rm /usr/local/bin/npm
- Recreate the sym link for the correct version of npm
ln -s /usr/bin/[email protected] /usr/local/bin/npm
Easier than messing up with Homebrew is to use asdf package manager. With that you can have multiple version of Node.js (as well as many other development tools) installed and configured running different versions in different directories. It looks like you can have it installed using Homebrew:
$ brew install asdf
Then you can install Node.js plugin using
$ asdf plugin-add nodejs
You can list versions of available Node.js versions by
$ asdf list-all nodejs
and choose the desirable versions to install, e.g.
$ asdf install nodejs 8.17.0
$ asdf install nodejs 14.4.0
You need to have asdf in your $PATH before anything else; I am not sure where these are if using Homebrew installed asdf, but Homebrew should tell you how to configure your shell profiles during installation.
You can activate a version of Node.js (and associated NPM) as a global default by
$ asdf global nodejs 14.4.0
or locally in the given directory (and subdirectories) with
$ asdf local nodejs 8.17.0
(which will just write .tools file in the directory specifying the desired version).
Each of the Node.js environment have their own global packets.
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
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.
I encountered the same issue. After searching and reading different things online, what worked for me was:
$ brew postinstall node
However, first please do execute:
$ brew doctor
and follow the instructions there first, like the comment in your question mentions.
Try the following:
$ brew update
$ brew uninstall node
$ brew install node
$ sudo chown -R YourLocalUserName /usr/local/lib/node_modules/
$ brew postinstall node