1

I’m using Mac Big Sur. I want to downgrade the version of Node. I tried the below (installing without sudo gives me permission errors) …

$ sudo n 14.15.1
   installed : v14.15.1 to /usr/local/bin/node
      active : v14.17.6 at /usr/local/opt/node@14/bin/node

But I still get the current version when I check

$ node -v
v14.17.6

Fwiw, here’s what I see with “which node”

$ which node
/usr/local/opt/node@14/bin/node

Edit: My $PATH when I run 'echo $PATH' ...

/usr/local/opt/node@14/bin:/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/usr/local/opt/node@14/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin

Edit 2: PATH vars for both regular user and sudo user ...

$ env | grep PATH
PATH=/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin

$ sudo env | grep PATH
PATH=/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
Aryan Beezadhur
  • 4,503
  • 4
  • 21
  • 42
Dave
  • 15,639
  • 133
  • 442
  • 830
  • did you install n globally or with brew? – MWO Dec 09 '21 at 18:31
  • Ooh, I don't remember. "which n" reveals /usr/local/bin/n is that helps. – Dave Dec 09 '21 at 19:10
  • You have removed /usr/local/opt/node@14 from PATH so hopefully fixed original problem, but now have added nvm so still got multiple nodes in PATH with /Users/davea/.nvm/versions/node/v14.18.1 – shadowspawn Dec 17 '21 at 22:45

1 Answers1

3

The n message is telling you that the version it just "installed" and the version that is "active" are different. You have two versions of node installed, and the active version is the one that is first in the PATH.

The active version is /usr/local/opt/node@14/bin/node. I don't recognise that path, not sure what was used to install that. It must be in your PATH variable and there might be a clue in your login script as to what added /usr/local/opt/node@14/bin to the PATH?

To get the n installed version of node to be the active version, you could delete the other copy of node, or put /usr/local/bin earlier in PATH so it is found first, or simplest remove /usr/local/opt/node@14/bin from your PATH variable.

shadowspawn
  • 3,039
  • 22
  • 26
  • Added output of my $PATH to my question. – Dave Dec 13 '21 at 15:16
  • @dave Something put /usr/local/opt/node@14/bin into your PATH. Have look in your shell startup script for what did that, and remove it since you want to be able to switch node versions using n. I will update my answer a little. – shadowspawn Dec 13 '21 at 20:33
  • There was a line in my "~/.bash_profile" that read "export PATH="/usr/local/opt/node@14/bin:$PATH"". I removed that, spawned a new shell, but the problem remains. – Dave Dec 14 '21 at 18:10
  • What is your PATH now? Check using "env" and "sudo env". By default sudo does not use the same environment variables as your current shell, so potential for differences there to add to the confusion! – shadowspawn Dec 14 '21 at 19:15
  • I do see a "/Users/davea/.nvm/versions/node/v14.18.1/bin" creeping in for both the sudo $PATH and regular user $PATH but I don't see a reference to this directory in either my ~/.bash_profile, ~/.profile or /etc/profile files. – Dave Dec 17 '21 at 20:56
  • The nvm directory has been added to your PATH by installing and using nvm. You mentioned trying nvm in another comment. To uninstall nvm see https://github.com/nvm-sh/nvm#uninstalling--removal – shadowspawn Dec 17 '21 at 22:41