Node version will not update using n
Asked Answered
T

1

8

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.

Turf answered 10/1, 2021 at 19:51 Comment(0)
P
10

The problem is you have node installed to two locations, and the one being installed by n is later 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"
Punke answered 10/1, 2021 at 21:51 Comment(1)
Hit the nail on the head. Thank you so much, @shadowspawn! Running n doctor showed: Checking n install destination priority in PATH... There is a version of node installed which will be found in PATH before the n installed version. By implementing the change suggested and re-sourcing the .zshrc file, everything seems to be working beautifully!Turf

© 2022 - 2024 — McMap. All rights reserved.