n (node version manager) not working after install - "bash: n: command not found"
Asked Answered
L

1

6

I would like to manage node.js versions using the n - node version manager.

I attempted to install n by following the Github docs https://github.com/tj/n and input the following in my terminal:

sudo npm install -g n

After entering my password my terminal returns:

/usr/local/lib/node_modules/node/bin/n -> /usr/local/lib/node_modules/node/lib/node_modules/n/bin/n
+ [email protected]

However, after installing n my terminal doesn't recognize the relevant commands and instead states:

bash: n: command not found

My current node version installed is v12.3.0, while my npm is version 6.9.0.

Any help would be greatly appreciated.

Thanks

Lamar answered 1/10, 2019 at 19:15 Comment(1)
For npm installed "'commands" to be found, the npm bin folder is added to your PATH environment variable. However, your install location looks deeper than expected so I think you have a setup issue first. What does npm prefix -g show? What OS are you on? What does command -v npm show?Marsh
M
10

The commands added using npm global packages are found by the the install location appearing in your PATH environment variable. You appear to have a misconfigured prefix, perhaps due to how node and npm are installed.

This is how things look in a typical setup. The bin folder under the npm prefix is included in PATH so the installed commands are found.

$ npm prefix --global
/usr/local
$ sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ [email protected]
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ command -v n
/usr/local/bin/n
$ n --version
6.0.1
Marsh answered 5/10, 2019 at 20:51 Comment(1)
Useful, thanks. I fixed my issue by updating ~/.npmrc to read "prefix=/usr/local" as mentioned abovePhrensy

© 2022 - 2024 — McMap. All rights reserved.