问题
To give some context, I set up my machine using this Medium post, Don’t Use sudo with npm …still.
I installed Node using brew
about a year and a half ago, which installed v12.18.1. I also installed n
at the time using brew
, but never had to change versions until now.
My .zshrc
file includes the following:
# For globally installed npm packages (without using sudo)
export PATH="$HOME/.npm/bin:$PATH"
# Path to n (managing node versions)
export N_PREFIX="$HOME/.n"
export PATH="$PATH:$N_PREFIX/bin"
When I install Node v14 with n
, the following occurs:
➜ ~ node -v
v12.18.1
➜ ~ n 14
installed : v14.15.4 to /Users/myusername/.n/bin/node
active : v12.18.1 at /usr/local/bin/node
➜ ~ node -v
v12.18.1
I see that the version was successfully installed; however, the active version doesn't update. I noticed that the path of the installed version is clearly different than the active version (reference terminal output above), which I suspect is the issue.
Any help would be greatly appreciated! Thank you in advance.
Additional information: When I installed Node initially, yarn
was not available despite the article linked at top stating it should be so I installed n
using brew
. To troubleshoot, I ran brew uninstall n
, however, the following was output:
Warning: The following may be n configuration files and have not been removed!
If desired, remove them manually with `rm -rf`:
/usr/local/etc/bash_completion.d
And so then I ran rm -rf /usr/local/etc/bash_completion.d
. Nothing printed to the terminal after.
回答1:
The problem is you have node
installed to two locations, and the one being installed by n
is last in the PATH
variable.
For interest, you can run n doctor
and it should pick up this problem.
You could either uninstall the copy of node installed to /usr/local/bin/node
, or rearrange your PATH
. Instead of:
export PATH="$PATH:$N_PREFIX/bin"
try:
export PATH="$N_PREFIX/bin:$PATH"
来源:https://stackoverflow.com/questions/65657802/node-version-will-not-update-using-n