Homebrew installs nvm but nvm can't be found afterwards?

前端 未结 10 1305
既然无缘
既然无缘 2020-12-22 20:53

I\'m using homebrew and oh-my-zsh on a fresh OSX 10.10.1 install. I got nvm via homebrew and then attempted to run it but

相关标签:
10条回答
  • 2020-12-22 21:16

    There are TWO things you need to do. Follow the caveats shown after installing nvm via brew, and THEN you need to activate/reload the .bash_profile changes.

    1. Run brew install nvm
    2. Follow caveats shown in console, mine were as follows, yours MAY be different!:

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

    export NVM_DIR="$HOME/.nvm"
    . "$(brew --prefix nvm)/nvm.sh"
    
    1. Run . ~/.bash_profile to apply the changes you made to your .bash_profile file
    0 讨论(0)
  • 2020-12-22 21:16

    One possibility if brew was used is that the nvm may be unlinked, especially if it was installed by another MAC OS user.

    In this case, execute:

    brew link nvm
    
    0 讨论(0)
  • 2020-12-22 21:20

    Did you follow the instructions listed in the caveats?

    [~] brew info nvm
    nvm: stable 0.20.0, HEAD
    https://github.com/creationix/nvm
    Not installed
    From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb
    ==> Caveats
    Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's
    equivalent configuration file:
    
      source $(brew --prefix nvm)/nvm.sh
    
    Node installs will be lost upon upgrading nvm. Add the following above
    the source line to move install location and prevent this:
    
      export NVM_DIR=~/.nvm
    

    Without the extra config it doesn't look like it will find NVM by default..

    0 讨论(0)
  • 2020-12-22 21:24

    The reason you would need to reload your bash profiles or any other bash files might be because the command nvm may not be a program but a function that is defined and can only be used if the corresponding bash file is sourced.

    On a system that I checked

    which nvm 
    

    does not work but

    nvm list
    

    does. This means that you can use the word "nvm" to invoke something. That something isn't a program. In the current case, it is a function which can be verified by

    typeset -F | grep -P ' nvm$'
    

    which outputs

    declare -F nvm
    

    which means nvm is a function, whose body can be inspected by doing

    type -F nvm
    
    0 讨论(0)
  • 2020-12-22 21:25

    To .bash_profile or .zshrc add:

    export NVM_DIR="$HOME/.nvm"
    source $(brew --prefix nvm)/nvm.sh
    

    But a second line makes terminal initialization slow. Solution: https://gist.github.com/gfguthrie/9f9e3908745694c81330c01111a9d642

    0 讨论(0)
  • 2020-12-22 21:29

    if you happen to be using fish shell, consider https://github.com/jorgebucaran/nvm.fish

    0 讨论(0)
提交回复
热议问题