Home > Enterprise >  npm install -g n appeared to work but n command not recognized
npm install -g n appeared to work but n command not recognized

Time:08-22

I am setting up a new Mac and trying to install n so that I can manage node versions for my development project. It works great on my old mac but I can't seem to get things sorted on the new Macbook Pro M1.

First, I installed it with npm install -g n and it reported that it installed the package:

npm i n
added 1 package, and audited 2 packages in 1s
found 0 vulnerabilities

But when I use n 10.14.1 to attempt to install a specific version of node, I get this error:

n 10.14.1
zsh: command not found: n

Update: Here is what I get from $PATH in terminal (I switched from zsh to bash so that I could try to match my old Mac's setup):

-bash: /opt/openssl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/opt/homebrew/bin: No such file or directory

My .bash_profile contents is:

export PATH="${HOMEBREW_PREFIX}/opt/openssl/bin:$PATH"

Update: My npm and corepack folders are located at /usr/local/bin/npm

Everything else I've installed (@angular/cli and n) is being placed in /users/[me]/.npm-global/lib/node_modules/

CodePudding user response:

You should add your .npm-global's bin folder in your $PATH

In your .bashrc or .profile, add:

export PATH=~/.npm-global/bin:$PATH

See point 4 of this doc

  • Related