How can I activate node version on mac
Asked Answered
C

4

5

I try to change the node version on mac m1 pro macOs 13, I do the following commands:

  1. sudo npm cache clean -f
  2. sudo npm install -g n
  3. sudo n stable

but it is not change, the result is:

copying : node/18.12.0
installed : v18.12.0 to /usr/local/bin/node
active : v17.8.0 at /opt/homebrew/bin/node

How can I activate the installed version?

Canaigre answered 30/10, 2022 at 19:14 Comment(2)
Seems the homebrew node version has priority, so uninstall the homebrew node version and then run hash -r or open a new shell. Or create a symlink to /usr/local/bin/node in a directory that has a higher priority in your PATH.Nez
I'll say go with nvm it lets you install multiple node versions and use them according to your project requirements.Kristinkristina
I
5

I had the similar case and I was able to resolve it like below

   installed : v20.8.0 to /usr/local/bin/node
      active : v16.15.0 at /Users/me/.config/nvm/versions/node/v16.15.0/bin/node

Command> node -v v16.15.0

nvm deactivate 16.15.0
nvm uninstall 16.15.0
Uninstalled node v16.15.0
Command> node -v
v20.8.0
Inexpressible answered 4/10, 2023 at 16:58 Comment(1)
This answer covers a conflict between nvm and n. The high level answer is appropriate, delete the "other" node. But you probably do not want two node version managers active.Magruder
M
1

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.

The two main options are

  • delete the other (homebrew) copy of node, or
  • alter PATH so /usr/local/bin is ahead of /opt/homebrew/bin (but homebrew may want to be first!)

The best option with a homebrew conflict is probably to uninstall the homebrew managed version of node. Assuming you don't have global packages installed other than npm itself:

Short version:

npm uninstall --global npm
brew uninstall node

Long version: the n documentation recently added this very case in a detailed walkthrough: https://github.com/tj/n/blob/master/docs/changing-node-location.md

(Disclaimer: I am a maintainer of n.)

Magruder answered 20/5 at 8:16 Comment(0)
M
0

Step 2 and 3 are the same so maybe you did it but… you can try to n uninstall 17.8.0 followed by sudo n to select the desired version.

Magpie answered 30/10, 2022 at 19:20 Comment(0)
R
0

The active node is installed using homebrew. Therefore, you could remove the node installed using the homebrew and install it from the Mac Installer from https://nodejs.org/en/download/.

In addition to that, you might need to add the path variable to .zshrc. For that, In your terminal nano ~/.zshrc then add the line:

export PATH=$PATH:/Users/[your username]/.npm-packages/bin

Also, if you need to use multiple node versions in a single machine you can use a node version manager[1].

[1] https://github.com/nvm-sh/nvm

Resident answered 30/10, 2022 at 19:37 Comment(1)
Note: n is a node version manager.Magruder

© 2022 - 2024 — McMap. All rights reserved.