Node Version Manager install - nvm command not found

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

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/install.sh | sh

After running the install, I restart the terminal and attempt to install Node.js with this command:

$ nvm install 0.8

but I get the response:

-bash: nvm: command not found

I'm not sure what I am doing wrong here.

Additional Info--

I've been looking around for solutions from other posts and forums. I found another solution using

$ git clone git://github.com/creationix/nvm.git ~/.nvm

but this times out every time I attempt that. Any help would be appreciated. Thanks.

回答1:

Check your .bash_profile 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


回答2:

I think you missed this step:

source ~/.nvm/nvm.sh

You can run this command on the bash OR you can put it in the file /.bashrc or ~/.profile to automatically load it

https://github.com/creationix/nvm



回答3:

In macOS, i had to source it using source ~/.nvm/nvm.sh command to fix this problem.

After that, add these lines

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

onto ~/.bash_profile so that nvm will be sourced automatically upon login.



回答4:

source ~/.nvm/nvm.sh Add this line to ~/.bashrc, ~/.profile, or ~/.zshrc



回答5:

This worked 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... - Don't forget to Restart your terminal OR use command source ~/.nvm/nvm.sh (this will refresh the available commands in your system path).

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



回答6:

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.



回答7:

If you are using OS X, you might have to create your .bash_profile file before running the installation command. That did it for me.

Create the profile file

touch ~/.bash_profile

Re-run the install and you'll see a relevant line in the output this time.

=> Appending source string to /Users/{username}/.bash_profile

Reload your profile (or close/re-open the Terminal window).

.  ~/.bash_profile


回答8:

Add the following lines to the files ~/.bashrc and ~/.bash_profile :

# NVM changes export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

and restart the terminal or do source ~/.bashrc or source ~/.bash_profile. If you need command completion for nvm then also add the line:

[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Along with the above lines to ~/.bashrc and ~/.bash_profile.



回答9:

Quick answer

Figure out the following:

  1. Which shell is your terminal using, type in: echo $0 to find out (normally works)
  2. Which start-up file does that shell load when starting up (NOT login shell starting file, the normal shell starting file, there is a difference!)
  3. Add source ~/.nvm/nvm.sh to that file (assuming that file exists at that location, it is the default install location)
  4. Logout/login
  5. Profit?

Example

As you can see below it states zsh and not bash.

To fix this I needed to add source ~/.nvm/nvm.sh to the ~/.zshrc file as when starting a new terminal my Deepin Terminal zsh reads ~/.zshrc and not bashs ~/.bashrc.

Why does this happen

This happens because when installing NVM it adds code to ~/.bashrc, as my terminal Deepin Terminal uses zsh and not bash it never reads ~/.bashrc and therefor never loads NVM.

In other words: this is NVMs fault.

More on zsh can be read on one of the answers here.



回答10:

I had fixed this problem.

  1. touch ~/.bash_profile
  2. open ~/.bash_profile
  3. pasteexport 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


回答11:

The nvm install script by default adds initialization code to your $HOME/.profile, which is only loaded by a login shell (in a desktop environment you may never see a login shell).

The nvm command in your login shell is not propagated to sub-shells (like console windows and IDE terminals after you log in). This snippet in your $HOME/.bashrc will only load nvm if it is an interactive shell and has not been loaded already

# if nvm dir is not set and the standard nvm directory exists if [ -z "$NVM_DIR" -a -d "$HOME/.nvm" ] ; then # set nvm dir   export NVM_DIR="$HOME/.nvm" fi  # if nvm dir is set and this shell is interactive if [ -d "$NVM_DIR" -a -n "$PS1" ] ; then   # if nvm command is not defined   if ! type -t nvm >/dev/null ; then     # set it     source "$NVM_DIR/nvm.sh"   fi fi

Putting this in your $HOME/.bashrc file will fix the missing nvm problem in interactive bash shells, even from a gui, and even if nvm is installed in a non-standard location.



回答12:

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.



回答13:

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



回答14:

For me this worked. First check that the file .bashrc has following line

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

Now bashrc is loaded for each terminal session. Thus restart the terminal so that it is loaded again and you should be good to go.



回答15:

In Windows 8.1 x64 same happened with me, and received the following message.

nvm install 8.3.0 bash: nvm: command not found windows

So, follow or verify below following steps-

first install coreybutler/nvm-windows from github.com. Currently available latest release 1.1.5 nvm-setup.zip, later extracted the setup nvm-setup.exe and install as following locations:

NVM_HOME    : C:\Users\Administrator\nvm NVM_SYMLINK : C:\Program Files\nodejs

and meanwhile setup will manage the environment variable to Path as above said for you.

Now run Git Bash as Administrator and then.

$ nvm install 8.3.0 all  Downloading node.js version 8.3.0 (64-bit)... Complete Creating C:\Users\Administrator\nvm\temp  Downloading npm version 5.3.0... Complete Installing npm v5.3.0...  Installation complete. If you want to use this version, type  nvm use 8.3.0  $ nvm use 8.3.0 Now using node v8.3.0 (64-bit)

here run your command without using prefix $, it is just shown here to determine it as a command line and now we will verify the nvm version.

$ nvm --version Running version 1.1.5.  Usage: -----------------------

if you have problem using nvm to install node, you can see this list of available nodejs releases here https://nodejs.org/download/release/ and choose the correct installer as per your requirement version equal or higher than v6.3.0 directly.



回答16:

I also faced the same problem recently and sourcing nvm bash script by using source ~/.nvm/nvm.sh resolved this issue.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!