Node Version Manager install - nvm command not found

后端 未结 26 1495
名媛妹妹
名媛妹妹 2020-11-30 16:18

I am trying to install NVM as per these instructions

I typed in this command in terminal:

$ curl https://raw.github.com/creationix/nvm/master/instal         


        
相关标签:
26条回答
  • On Debian, as well as adding the below lines to my .bash_profile as one of the above answers said. I also had to open up my terminal preferences (Edit -> Profile Preferences -> Command) and enable 'Run command as a login shell' to get it to work.

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
    

    Edit: For those on Mac be aware that macOS doesn't read .bashrc on Terminal start, so using .bash_profile is preferable. See Here.

    0 讨论(0)
  • 2020-11-30 16:45

    Not directly connected to the question, but there is a similar problem that may happen, take a look at this question: Can't execute nvm from new bash


    Here's my answer on that post, just for the reference:

    If you are running from a new bash instance, and you HAVE the initialization code at your ~/.bashrc, ~/.bash_profile, etc, then you need to check this initialization file for conditionals.

    On Ubuntu 14, there is a:

    case $- in
        *i*) ;;
          *) return;;
    esac
    

    At line 6, that will halt it's execution if bash is not being ran with the "-i" (interactive) flag. So you would need to run:

    bash -i
    

    Also, at the end of the file, there is a

    [ -z "$PS1" ] && return
    

    That will halt it's execution if not being ran with $PS1 set (like on a remote ssh session).

    If you do not wish to add any env vars or flags, you will need to remove those conditionals from your initialization file.

    Hope that's helpful.

    0 讨论(0)
  • 2020-11-30 16:45

    I have the same problem and what saved my life is the sentence "you may have to add to more than one of your "~/.bashrc, ~/.profile, or ~/.zshrc files". the following lines were in my .bashrc only, I added it to files ".bash_profile" and ".profile" and worked for me .

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    
    0 讨论(0)
  • 2020-11-30 16:45

    For my case, it because I use fish. if I not start fish, just type nvm will no error now.

    0 讨论(0)
  • 2020-11-30 16:48

    Check your .bash_profile, .zshrc, or .profile file. You most likely had a problem during the installation.

    You should have the following at the end of one of those files.

    [[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh  # This loads NVM
    

    The . $HOME/.nvm/nvm.sh is the same as source $HOME/.nvm/nvm.sh

    See: Sourcing a File

    You can also check to see if you have a .nvm folder.

    ls -a | grep .nvm
    

    If you're missing that folder then the installation failed to run the git command. This could be due to being behind a proxy. Try running the following instead.

    git clone http://github.com/creationix/nvm.git .nvm
    
    0 讨论(0)
  • 2020-11-30 16:48

    This works for me:

    1. Before installing nvm, run this in terminal: touch ~/.bash_profile

    2. After, run this in terminal:
      curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash

    3. Important... - DO NOT forget to Restart your terminal OR use command source ~/.nvm/nvm.sh (this will refresh the available commands in your system path).

    4. In the terminal, use command nvm --version and you should see the version

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