Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-bash: nvm: command not found #576

Closed
apaternite opened this issue Nov 12, 2014 · 155 comments

Comments

Projects
None yet
@apaternite
Copy link

commented Nov 12, 2014

Running terminal in Mac OS X Yosemite.

Followed the installation instructions and restarted terminal:
curl https://raw.githubusercontent.com/creationix/nvm/v0.18.0/install.sh | bash

When using nvm I always get -bash: nvm: command not found

When installing again:
=> nvm is already installed in /Users/Tony/.nvm, trying to update
=> HEAD is now at 5f5eb47... v0.18.0

I do have npm already installed. Does that matter?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Nov 13, 2014

Having node and npm already installed doesn't matter.

However, you do need to nvm use before nvm will take over your PATH and let you use nvm's version of node.

Can you check your ~/.bash_profile and ~/.bashrc for the relevant nvm lines, and paste them here? Also, what does echo $PATH say on a new shell?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Nov 22, 2014

Please reopen if you discover this is actually a problem with nvm.

@ljharb ljharb closed this Nov 22, 2014

@alfredbez

This comment has been minimized.

Copy link

commented Dec 4, 2014

I had the same issue until I added the following lines to my .bash_profile

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Dec 4, 2014

Hmm, install.sh should add those to .bashrc or .bash_profile for you, which if you'd manually created it, should be sourced inside bash_profile. Perhaps that's the issue, that bashrc exists but isn't sourced inside bash_profile?

@am11

This comment has been minimized.

Copy link

commented Jan 16, 2015

I was having the same issue. After installing nvm, I had to exit from bash and re-login to make it work (I read it somewhere earlier). I think we should update the README.

Tried on CentOS 7 in VM (dev installation mode, CLI only).

@jeancdc

This comment has been minimized.

Copy link

commented Apr 4, 2015

Hi,

I've got the same problem on Mac OS X 10.10 Yosemite. I've installed nvm with the command :
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash

This add the following lines in my .bashrc file:
export NVM_DIR="/Users/jeancreuzedeschatelliers/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

And I also add the following line at the bottom of the same file:
source ~/.nvm/nvm.sh

But it doesn't work. I must execute this last command every time I want use nvm.

Any idea ?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2015

@jeancdc . something and source something are the same, except that the . is more portable, so you should definitely remove that redundant source line.

However, unless you run something like nvm alias default stable, every shell is intended to start with nvm in a deactivated but available state. Perhaps that's the issue?

@jeancdc

This comment has been minimized.

Copy link

commented Apr 4, 2015

  • I've removed the source ~/.nvm/nvm.sh line,
  • install a version of node with nvm install 0.12.2
  • use this default version of node with nvm alias default 0.12.2

But still the same problem when I quit the terminal and restart it... I must execute source ~/.nvm/nvm.sh every time I launch the terminal...

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2015

export NVM_DIR="/Users/jeancreuzedeschatelliers/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm - this should be two lines, like so:

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

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2015

@jeancdc does that fix your issue?

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

It was already two lines. Maybe I made wrong when I copied-paste this.
But still the same problem... :-(

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

OK, I've done the same thing than @alfredbez and it works:

Like he said, I must to add the following lines at the end of the ~/.bash_profile file:

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

Maybe the author @creationix should add these instructions in the README.markdown file.

Thanks to you !

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2015

@jeancdc Usually the install script does it for you, so nothing is needed in the readme. what OS are you using?

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

I use Mac OS X 10.10.2 Yosemite

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2015

@jeancdc I'm not sure how you installed nvm, but the install script should have done that for you. How did you install it?

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

with this command:
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2015

yup, that should do it. On a hunch - do you use any other shells? What does ls -a ~ | \grep -e '^\.' output? (ie, what other dotfiles do you have)

It's possible that it's already in your .bashrc file, and the problem is just that your .bash_profile doesn't source .bashrc anywhere in it.

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

I use the default terminal.

This is the result of the command:

.
..
.CFUserTextEncoding
.DS_Store
.MacOSX
.MakeMKV
.OpenCobolIDE
.Scilab
.Trash
.WebStorm9
.Xauthority
.adobe
.android
.avidemux
.bash_history
.bash_profile
.bash_profile.macports-saved_2012-01-22_at_20:47:07
.bash_profile.macports-saved_2014-06-03_at_21:50:12
.bash_profile.macports-saved_2014-10-18_at_22:28:07
.bash_profile.pysave
.bash_profile.swo
.bashrc
.bundle
.cache
.codeintel
.composer
.config
.cordova
.cups
.dbus-keyrings
.dtLiteMacLicense.dat
.dvdcss
.eclipse
.eclipse_keyring
.f-secure
.filezilla
.fontconfig
.gem
.gitconfig
.gitignore_global
.gnome2
.goodsync
.gradle
.heroku
.hgignore_global
.idlerc
.inkscape-etc
.lincity-ng
.local
.m2
.macports
.matlab
.mkshrc
.mplayer
.mypaint
.nchsoftware
.netrc
.nexuiz
.node-gyp
.npm
.nvm
.pdfsam
.pgpass
.pia_manager
.pia_manager_crash.log
.plugman
.profile
.psql_history
.rnd
.rvm
.serverauth.81878
.serverauth.981
.sqlite_history
.ssh
.subversion
.swt
.thumbnails
.viminfo
.widelands
.windows-serial
.wine
.xinitrc.d
.zlogin
.zshrc
@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2015

If you check .bashrc and .zshrc and .profile, do any of them contain the nvm sourcing lines?

If so, then it's that the install script's shell detection is a bit wonky.

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

Here is what there are in the ~/.bashrc file:

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

Nothing in the ~/.zshrc and in the ~/.profile files related to NVM.

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2015

Gotcha, thanks. Adding source ~/.bashrc to your .bash_profile would have resolved it as well.

@jeancdc

This comment has been minimized.

Copy link

commented Apr 5, 2015

So, does that mean that the install script of NVM need some fix ?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2015

Yes, #592 is probably the closest issue to it.

@wonderdogone

This comment has been minimized.

Copy link

commented Jul 14, 2015

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

in /etc/profile worked for me

@ysk8

This comment has been minimized.

Copy link

commented Aug 6, 2015

The solution of @wonderdogone works for me. Before, I tried the solutions suggested by @ljharb in response to @jeancdc.

Is possible that the problem is related with the permissions of the .bashrc file?

Is the best way to solve this issue, edit the profile file like @wonderdogone comment? Again, that solution works for me too.

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Aug 6, 2015

The installation script's primary jobs are:

  • download nvm to $HOME/.nvm
  • add the "source nvm" lines to the appropriate shell profile file.

The second one is extremely difficult and error-prone. If at any time it fails for you, adding those two lines (#576 (comment)) to the appropriate profile file for your shell should solve it.

@OClement

This comment has been minimized.

Copy link

commented Oct 21, 2015

I had that issue as well in Yosemite
I was using ~/.bashrc with no success
Replacing this file to use ~/.profile instead fixed the issue

It seems the .bashrc file isn't loaded anymore?

@nahumzs

This comment has been minimized.

Copy link

commented Jul 21, 2018

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVM at the end of .zshrc https://stackoverflow.com/questions/16904658/node-version-manager-install-nvm-command-not-found#

@diegoagd10

This comment has been minimized.

Copy link

commented Jul 31, 2018

I have oh-my-zsh installed, I had to add at my .zshrc file the following line:

source ~/.bash_profile

That fixed the issue.

@dgaeta

This comment has been minimized.

Copy link

commented Aug 19, 2018

Add the following to your ~/.bash_profile file and don't forget to restart your terminal 💯 hehe

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
@parthmakadiya12

This comment has been minimized.

Copy link

commented Sep 4, 2018

I solved the issue by doing these(suggested by various answers ) -->

  1. run this command
    ls -a ~ | \grep -e '^\.'
  2. look .bash_profile .bashrc or .zshrc
  3. Add these line of code at the end of the relative file for me it was zshrc and it was working fine
    export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm export NVM_DIR=~/.nvm source ~/.nvm/nvm.sh
  4. Restart the terminal

Done.

@kristjankoppel

This comment has been minimized.

Copy link

commented Sep 12, 2018

I use zsh and i had to add these two lines:
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

Into ~/.zshrc file.

So this command not found problem still exists.

@swthate

This comment has been minimized.

Copy link

commented Oct 10, 2018

I was having the same problem. I opened ~/.bash_profile and everything looked fine until I noticed a strange escaped-looking character:

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

Changing \. to simply . between && and "NVM_DIR/... on both lines fixed my problem.

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Oct 10, 2018

@swthate that backslash is intentional; it ensures you can’t override the dot operation.

What shell are you using?

@swthate

This comment has been minimized.

Copy link

commented Oct 10, 2018

Oh, thanks for that heads up, @ljharb . I'm using bash (usually inside either PHPStorm or Hyper terminal).

I just opened bash_profile again and the backslashes are back. But nvm is still working when I relaunch any bash shell. For now. Strange.

@AdrianAntunez

This comment has been minimized.

Copy link

commented Oct 11, 2018

I'm just curious, why is not ~/.nvm/nvm.sh sourced from the installation script to avoid having to source it or close and reopen the terminal manually?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Oct 11, 2018

@AdrianAntunez that's not possible, since the installation script is piped to bash (or sh or zsh or whatever) - it'd have to be sourced to be able to source something into your own shell.

@JustEugen

This comment has been minimized.

Copy link

commented Oct 12, 2018

@kristjankoppel thank you too much

@OndeVai

This comment has been minimized.

Copy link

commented Nov 6, 2018

Ugh, that install hurt my night. Ran into the same issue with bash command not being recognized. However, these hidden little instructions from the readme for this repo got me through:

Note: On OS X, if you get nvm: command not found after running the install script, one of the following might be the reason:-

your system may not have a [.bash_profile file] where the command is set up. Simply create one with touch ~/.bash_profile and run the install script again
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, open your .bash_profile and add the following line of code:

source ~/.bashrc

@boochamoocha

This comment has been minimized.

Copy link

commented Nov 7, 2018

Have save problem bash: nvm: command not found and bash: npm: command not found only if execute commands like this
ssh user@server "nvm --version"

If i try to use commands directly after login via ssh - it works fine

ssh user@server
server> nvm --version

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Nov 7, 2018

@boochamoocha try ssh -l to log in with a login shell.

@boochamoocha

This comment has been minimized.

Copy link

commented Nov 7, 2018

@boochamoocha try ssh -l to log in with a login shell.

Hi. -l flag is login name for ssh by man. Can you please explain how to use ?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Nov 7, 2018

ssh -l user@server “nvm --version”

@boochamoocha

This comment has been minimized.

Copy link

commented Nov 7, 2018

ssh -l user@server “nvm --version”

Argument after -l is login name. And next one is hostname. Command you suggested is return Could not resolve hostname nvm --version.

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Nov 7, 2018

Fair enough, my command is clearly incorrect - regardless, unless you ssh as a login shell then you won't have nvm available.

@boochamoocha

This comment has been minimized.

Copy link

commented Nov 7, 2018

Fair enough, my command is clearly incorrect - regardless, unless you ssh as a login shell then you won't have nvm available.

Thank you for glue.
It works when use in this manner
ssh user@host -t 'bash -l -c "nvm --version;bash"'

@garfieldnate

This comment has been minimized.

Copy link

commented Nov 18, 2018

I was having this problem on Mac OSX, so I added the source ~/.bashrc line to my .bash_profile. However, this caused an infinite loop because the .bashrc file generated by the NVM install script contains this line:

[ -n "$PS1" ] && source ~/.bash_profile;

The conditional was always true, and the .bash_profile and .bashrc files were loading each other forever. I fixed the problem by removing that line.

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Nov 18, 2018

@garfieldnate nvm does not generate a bashrc file whatsoever; that file must have already existed on your machine.

@garfieldnate

This comment has been minimized.

Copy link

commented Nov 18, 2018

@ljharb Well, I feel bashful! You are right. I somehow got confused while reading the instructions and put the .bash_profile lines into .bashrc. The .bashrc line that caused the infinite loop was from the default .bashrc in matthiasbyrens' popular dotfiles repo for Mac OSX.

@leeeGreat

This comment has been minimized.

Copy link

commented Jan 4, 2019

如果在zsh命令行中提示nvm找不到
在 ~/.zshrc 中再次添加原nvm在 ~/.bashrc 中的配置,并 source ~/.zshrc 即可,参考 https://www.cnblogs.com/fanlinqiang/p/8395337.html

@bilalahmed54

This comment has been minimized.

Copy link

commented Feb 18, 2019

I also encountered the same issue.

I installed the NVM using the following command:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

And according to the documentation:

The command given above clones the nvm repository to '/.nvm' and adds the source line to your profile (/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

But this didn't work as there was no such file in my machine. You may verify by the following:

cd
ls -a

If there is no such file then create one. After this add the following line in the .bash_profile:

export NVM_DIR=~/.nvm

Restart CMD or opened a new tab and now, you should be able to access NVM.

@youryida

This comment has been minimized.

Copy link

commented Mar 5, 2019

如果在zsh命令行中提示nvm找不到
在 ~/.zshrc 中再次添加原nvm在 ~/.bashrc 中的配置,并 source ~/.zshrc 即可,参考 https://www.cnblogs.com/fanlinqiang/p/8395337.html

thx,my zsh is work.

the ~/.zshrc file need add some config:

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

then, run "source ~/.zshrc".

@allysson-esparta

This comment has been minimized.

Copy link

commented Mar 11, 2019

如果在zsh命令行中提示nvm找不到
在 ~/.zshrc 中再次添加原nvm在 ~/.bashrc 中的配置,并 source ~/.zshrc 即可,参考 https://www.cnblogs.com/fanlinqiang/p/8395337.html

thx,my zsh is work.

the ~/.zshrc file need add some config:

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

then, run "source ~/.zshrc".

Thanks it's work for me

@ashleyjelks

This comment has been minimized.

Copy link

commented Apr 1, 2019

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

in /etc/profile worked for me

This also worked for me in 2019...not sure why this step is required!

@quangkeu95

This comment has been minimized.

Copy link

commented Apr 11, 2019

如果在zsh命令行中提示nvm找不到
在 ~/.zshrc 中再次添加原nvm在 ~/.bashrc 中的配置,并 source ~/.zshrc 即可,参考 https://www.cnblogs.com/fanlinqiang/p/8395337.html

thx,my zsh is work.

the ~/.zshrc file need add some config:

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

then, run "source ~/.zshrc".

Worked for me with zsh

@tdriley

This comment has been minimized.

Copy link

commented Apr 29, 2019

I was having this issue on Ubuntu 18.0.4 and (similar to @JennieJi 's answer above) the solution was to remove the lines:

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

from ~/.bashrc and ~/.profile and put them in ~/.bash_profile. That was it - reboot and nvm was there ready to use.

@anivle

This comment has been minimized.

Copy link

commented May 21, 2019

On MacOS Mojave with zsh adding nvm sourcing lines to .zshrc solved the problem:

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

Thanks to @ljharb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.