".nvm" not in PATH - Apple M1 Macbook
Asked Answered
B

4

5

I am using an Apple M1 Macbook pro, with the 'zsh' terminal, and there are issues installing Node with the command "nvm install node". After trying that nvm command, I went ahead and downloaded Node directly from https://nodejs.org/en/download/

I want to make sure that the node installation references the directory NVM installs node via the PATH. However, this is what I am seeing.

When I run the command "which node", I get the following current output. I have listed the expected output as well. Is there a way to fix this?

Current output: /usr/local/bin/node
Expected output: /Users/username/.nvm/versions/node/v14.15.4/bin/node
Breunig answered 13/1, 2021 at 13:19 Comment(3)
try brew install nvmReplevin
nvm is already installed, the issue was installing node with nvm. So, I had to install node separately via the node.js website.Breunig
I wasn't having much luck with modifying .zshrc or path, etc. I'm using nvm also and found that this worked for me: nvm alias default <node_version> so for you nvm alias default 14 — See this threadAnemography
C
7

It's mentioned in nvm Github readme.

TLDR

Copy below code to your .zshrc file:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Camey answered 3/11, 2022 at 11:22 Comment(0)
B
5

if you take a closer look at nvm installation instructions, you will notice that there is an information about how to set a deeper shell integration.

it is even noted in brew

$ brew info nvm
...
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

Add the following to /Users/geek/.bash_profile or your desired shell
configuration file:

  export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.

Type `nvm help` for further information.

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

since you are interested in zsh deeper shell integration, do this (i intentionally do not include a snippet from the official documentation, so it will be up-to-date)

Buran answered 16/1, 2021 at 10:22 Comment(0)
H
3
  1. open terminal and run

git clone https://github.com/nvm-sh/nvm.git ~/.nvm

  1. run

source ~/.nvm/nvm.sh

Heimlich answered 7/5, 2022 at 8:48 Comment(0)
T
0

If you get nvm: command not found after running the install script, one of the following might be the reason:

Since macOS 10.15, the default shell is zsh and nvm will look for .zshrc to update, none is installed by default. Create one with touch ~/.zshrc and run the install script again.

If you use bash, the previous default shell, your system may not have .bash_profile or .bashrc files where the command is set up. Create one of them with touch ~/.bash_profile or touch ~/.bashrc and run the install script again. Then, run . ~/.bash_profile or . ~/.bashrc to pick up the nvm command.

You have previously used bash, but you have zsh installed. You need to manually add these lines to ~/.zshrc and run . ~/.zshrc.

You might need to restart your terminal instance or run . ~/.nvm/nvm.sh. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.

If the above didn't help, you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.

If the above doesn't fix the problem, you may try the following:

If you use bash, it may be that your .bash_profile (or ~/.profile) does not source your ~/.bashrc properly. You could fix this by adding source ~/<your_profile_file> to it or follow the next step below.

Try adding the snippet from the install section, that finds the correct nvm directory and loads nvm, to your usual profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

For more information about this issue and possible workarounds, please refer here

Note For Macs with the M1 chip, node started offering arm64 arch darwin packages since v16.0.0 and experimental arm64 support when compiling from source since v14.17.0. If you are facing issues installing node using nvm, you may want to update to one of those versions or later.

Tuque answered 19/6, 2023 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.