Nvm: -bash: nvm: command not found

Created on 12 Nov 2014  ·  167Comments  ·  Source: nvm-sh/nvm

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?

profile detection needs followup

Most helpful comment

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

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

All 167 comments

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?

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

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

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

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?

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).

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 ?

@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?

  • 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...

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

@jeancdc does that fix your issue?

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

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 !

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

I use Mac OS X 10.10.2 Yosemite

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

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

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.

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

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.

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.

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

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

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

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

in /etc/profile worked for me

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.

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 (https://github.com/creationix/nvm/issues/576#issuecomment-121381372) to the appropriate profile file for your shell should solve it.

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?

@OClement iirc it's not loaded by default in OS X unless bash_profile is not present. Do you have one of those?

No I actually didn't have any of these files in my home folder (be it bashrc, profile, bash profile and the likes)

I have to say I never was really clear about the differences between one or the others

indeed, that's the issue - simply having an empty one of those should make the install script work.

Good to know
Thanks for the precision!

@jeancdc The README still has remains of my original instructions under the "Manual Install" section. https://github.com/creationix/nvm#manual-install

This does mention to add the source line to your shell's startup script.

Though if you want to see how little of my original code is left unmodified, run a git blame. @ljharb and other contributors have done amazing work with this project.

This answer helped me on Mac OS X 10.11:
http://apple.stackexchange.com/a/119714
Basically it says that .bashrc is not loaded by Mac OS X, but .bash_profile is. So many put this in the latter:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

Before nvm installation I had neither of the files. And the installation created .bashrc with the code already mentioned in above comments.

What @alfredbez recommended worked for me on OSX 10.11

This worked for me on OS X 10.10.4:

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

@ljharb thanks!

I also didn't have any of the mentioned profiles in HOME. When installing nvm, no source scripts were added or modified. I had to create a ~/.profile file and add the lines from this comment.

@ljharb As I installed the nvm using command "curl", definitely it appended
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm to .bashrc file.
But there are some difference between .bashrc and .bash_profile that would cause "nvm command not found" error when using nvm after installing.
For the detail of the difference, please refer to http://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc

In the latest debian it also doesn't edit the ~/.bashrc

The documentation in README.md should be updated to reflect the likelihood of this problem. The proper solution is to run these commands or add them to your bashrc manually.

export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

This is especially painful for my non-javascript coworkers who already think this ecosystem is flaky.

@chrisinajar I'm always open to PRs that improve the README, or improve profile detection.

Message for the team:

I noticed that most comments here are from users running OS X Yosemite. I also came here with the same issue running the same OS. Maybe a reference, on the Readme or some coding wizardry (if possible) to reference on this OS that the source comes from .bashrc (as mentioned here), would be a good fit for all. You know, just suggesting.

Message for users:

For people struggling with NVM installs on Yosemite, this comment from @ljharb did the trick for me.

On your .bash_profile file, just add:

source ~/.bashrc

And 😎

@cezaraugusto a PR to the readme would be most welcome.

Warning: nvm-0.29.0 already installed
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.

My system is 10.12, is now impossible,
-bash: nvm: command not found
How to do?

@boai where did you see the message "We do not provide support for this pre-release version."? That seems like it might come from gcc or similar, but not from nvm. Either way, please try with the latest version of nvm, which is v0.31.2 - v0.29.0 is 9 months out of date - and then please file a new issue since "OS X 10.12" makes it seem like a different problem.

@ljharb Thank you! Yesterday I downgrade to 10.11, and then like, is estimated to be 10.12 system problems!

I have the same issue, so I adding source ~/.bashrc to .bash_profile, but it always show me "nvm: command not found" . At last, I found I have not add the enviroment params. So the I think the correct steps to fix this issue is like:
(1) Add following lines to ~/.bashrc, ~/.profile, or ~/.zshrc file
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
(2)Add source ~/.bashrc to your .bash_profile.

@susan-github I add source ~/.bashrc to ~/.zshrc file and fixed it.

@kimonoki you really don't want to do that, since zsh might choke on bash syntax. instead, copy the two nvm-related lines from bashrc to zshrc.

@ljharb Thanks for reminding that I was about to do that but somehow end in adding the source line. Now it's fine.

For the new ones like myself:

If you edit all those files, and still it doesn't work, you may need to run:
nvm install node

@franciscocorrales Thanks for posting. That was my missing step. All is well now.

Hi, I'm trying to get nvm installed on a Mavericks Mac, but this step is tripping me up. I had no ~/.bashrc file at all. I tried making one of those, a ~/.profile, and adding a bunch of the commands above to these files along with the ~/.bash_profile I made from scratch from the nvm instructions, but nothing worked to get nvm installed. Any more advice?

@gdvine make sure ~/.bash_profile has . "$HOME/.bashrc" in it, and then touch "$HOME/.bashrc", and then rerun the install script.

Hi, exactly same issues here. I use El Capitan, and I do not have any of these bash files. How can I fix this? I am quite new dealing with code. Tried all your solutions anyway, didn't worked.
If I try the command touch ~/.bash-profile for example, it seems that it exists already, but can not be used or found after when I do npm install/start. When I look for it, the message is "No such file or directory". Same for the .zshrc, .profile or .bashrc files. They are nowhere.
If someone can help, thank you!

@PatateFrite after the touch command, rerun the nvm install script (not npm install or npm start, those are for after you've got node working)

@ljharb yes, it's what I have done several times. I rerun the nvm install script first. Still same problem.

@PatateFrite ah. touch ~/.bash_profile - underscore, not dash.

@ljharb yes...I have done it that way on the terminal :(
once I have done this, and rerun the install script, when I verify, nvm is right there. If I use after that npm install and start, everything goes wrong. No more nvm, and my bash files are nowhere to be found. It's like everything is erased once I start npm....

@PatateFrite that sounds like it's probably some issue with whatever project defines "npm start" (since that's not an npm thing, that's just npm running a project script). If you file a new issue, we can investigate that separately.

@ljharb sorry, my mistake. It was a problem with the start in the package. Thanks for the help!

Hi, I can't seems to wrap this idea. I follow the readme. I didn't have .bashrc and .profile in my User folder. I see alot of comments about Adding , but i dun even know where to add. How to I "add" this code.

I've created a .bashrc and .profile but where to I add this code? In terminal or something?

I run the code from Manual Install and after that I can see node -v and npm -v installed but after which I close Terminal, and rerun Terminal. I type node -v again, it shows command not found.

@nickngqs .bashrc and .profile are files that live inside $HOME. Your specific issue seems like it's solvable with nvm alias default node, which will set a default node version to be used on new terminals - without which, you always must nvm use something before node is available.

@ljharb It doesn't work, typing nvm -v also shows command not found.

I've did the Manual Install method from the README. I've went through the first time, everything is okay, i checked nvm, node, npm, everything is there. But when I close the terminal and reopen it, everything is gone.

I've cloned nvm and it's still there in my $HOME, I've also have the npm folder in my $HOME. But right now when i type nvm -v or npm -v or node -v, it shows command not found.

@nickngqs can you file a new issue with the output requested by the template? It'll be easier to debug there than on this already large thread.

Sure, I've opened a new issue #1373

Hey guys, I Had the problem with the zsh and all I had to do is basically restarting it maybe the author should add that to the Readme.

@MohamedHajr the install script already explicitly tells you to restart your terminal after it's done.

It's possible that problem could happen when people are copying the whole line without " | bash" in the end, thinking it is a note to a user.

Interesting idea, that would be a new one.

just add export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
to ~/.profile
If the file doesn't exist do:
touch ~/.profile

Another solution is to run (everytime on a new shell):
source ~/.bash_profile which is so annoying

@vishakha94 Both of those are listed in the readme under "Manual installation".

I ran through the steps to install nvm and when I went to verify that it installed using; command -v nvm it returned nothing.

Below are 3 screenshots detailing the steps I took and the result I got. Please advise.

screen shot 2017-02-21 at 10 41 18 pm
screen shot 2017-02-21 at 10 41 35 pm
screen shot 2017-02-21 at 10 41 56 pm

Also, I was confused by the steps to install nvm manually. Can someone clarify?
screen shot 2017-02-21 at 10 39 02 pm

@Mohamoud which part confused you?

@ljharb I got it to work after adding the syntax to the different files. Thanks anyway.

I have added:

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

to .bashrc, .zshrc, .profile && .bash_profile files. Still not working‼!!

Do I have to restart my mac?

All I want to do is update my nodejs!!!!

@Maggieryder you have to restart your terminal, yes. did you run the install script in the readme?

Well, I am not so good at shell commands and get struggled cause I tried everything in any answers and still cannot work. In the end, I found the solution out by myself.

Need to mention that, nvm install scripts works pretty well on my OSX and ubuntu 14/15 machines, but somehow it breaks on a windows 10 machine using bash (ubuntu 14 core).

So what those commands above are just trying to do 2 things:

  1. export a global environment variable as $NVM_DIR, which might be used elsewhere
  2. tell your shell that you need to run '~/.nvm/nvm.sh' when initialize

So, actually what really works for me is:

  1. Remove all those lines contains 'nvm.sh' and 'NVM_DIR' from elsewhere like ~/.bashrc, ~/.zshrc, ~/.profile or whatever you've done when you try to make it work... I found they do cause conflicts and make it broke.
  2. Put following lines to ~/.bash_profile
export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

This answer was modified since I found my mistakes.

@JennieJi ~ is the same as $HOME, however i think zsh is inconsistent in that respect, and that's just something you have to know. Similarly, if you're choosing to use zsh, one of the costs of that choice is memorizing that .bashrc, bash_profile, etc are served in zsh by .zshrc. If you think the docs could be improved in that respect, a PR would be quite welcome!

@ljharb Thanks for your reply. I modified some contents of my last answer since I found it was wrong.

If it's not working, try closing the terminal and reopening it again.

(which is what the install script literally tells you to do inline after it's done ;-) )

Run . ~/.bash_profile to restart bash. You don't need to close and reopen it...

@matrixfox Thank you, solve my problem

I have the same problem , even if I add the two line to .bash_profile

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

the above steps are not enough, the last step that you should do is running source .bash_profilein the terminal

@SunShinewyf nvm is not supported at all when installed via homebrew. please install it properly via the curl script in the readme.

Put following lines to ~/.bash_profile:
export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

it has helped me

@MaxJaison
Hi did you just paste it or replace it?
I pasted it like this....

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
export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

but when I reopen the terminal it shows.......
-bash: echo: write error: Broken pipe

p.s. the weird part is when I use -v nvm it shows
-bash: -v: command not found
but when I type nvm --version
it shows the current version I just installed........

update-------------
now it shows
-bash: bash_completionexport: command not found

@BawLeeFanZ you're sourcing nvm.sh twice. You should remove the last two lines out of those 5.

@BawLeeFanZ i just paste this:

export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

I didn`t paste this:

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

@ljharb Hi~ thank you for reply~
After deleted the last two lines, when I tried -v nvm still showing -bash: -v: command not found
And I also found that there isn't any ~/.zshrc, ~/.profile, or ~/.bashrc exist, should I touch them and add those two lines by myself?
According to the discussion above, it seems like adding
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 in ~/.bash_profile is enough?

btw, my OS version is Sierra 10.12.5

p.s.1 Using the way that @MaxJaison mentioned also didn't work......
(update) 2.I installed the npm before nvm, is that the reason causing the issue?

@BawLeeFanZ not -v nvm, command -v nvm - include the word "command".

Yes, on OS X you can add those lines just to .bash_profile and that should be fine.

npm isn't installed by itself - it comes with node. It's fine if you have a system node; nvm will just shadow it as needed.

when I open the terminal ,it will show“ -bash: /usr/local/opt/nvm/nvm.sh: No such file or directory”
But I have add it to PATH.......

@CrazyForName that means you installed it with homebrew; try brew uninstalling it, and removing all nvm-related lines from all your shell profile files, and then re-run the curl + install script (as documented in the readme)

If you use fish terminal nvm doesn't work. Only solution for me was change back to default bash.

Thank you very much
🤣🤣🤣🤣

@ZuyRzuuf yes, fish is not POSIX compliant, so nvm won't ever work on it.

Had the same issue on Mac OS Sierra (10.12.6). Manually adding the below code into my .bash_profile.
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

@ahimsauzi that's what the install script should do for you; you may need to rerun it after updating the Mac OS (but you shouldn't have to)

As per the official docs. The text goes as below

Now add these lines to your ~/.bashrc, ~/.profile, or ~/.zshrc file to have it automatically sourced upon login: (you may have to add to more than one of the above files)

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

@kushalmahajan yes, in the official docs under "git install"; but if you followed the install script instructions that isn't necessary.

@kushalmahajan I used the curl install script and it did not update my .bash_profile, .profile or .bashrc. Perhaps, it was a permission and adding sudo in front of it would have solved it? Either way, after adding the needed lines manually everything works as expected.

@ahimsauzi thanks, if you could file a new issue about that that'd be appreciated! sudo should never be required.

@ljharb. Indeed. Infact, I didn't encountered it in first go. My task was to update npm manually. So for that some commands led to nvm not found too. Anyway, idea was to help load nvm again( assuming any scenario which may have rendered it useless).

@ahimsauzi You can try doin vim .bashrc in your root user and so forth for other files and add the export statement manually.

Issue:

I used the curl install script, and my .bash_profile did get updated.

But on my Mac OS X 10.11 El Capitan at least, the LINE ENDINGS turned out to be 0d 0a instead of what Mac wants - 0a.

This caused : command not found errors on opening a new Terminal window.

Debugging using $ bash --login -x revealed the complaints about the line endings (bit obliquely).

Bit of hexdump confirmed assumptions.

Manual Edit Fix:

As noted by others, manual edit to the .bash_profile (getting rid of the lines supplied by the curl install script) got things to work.

Notes:

$ bash --login -x
...
+ $'\r'
: command not found
+ $'\r'
: command not found
+ export $'NVM_DIR=/Users/william.reilly/.nvm\r'
+ NVM_DIR=$'/Users/william.reilly/.nvm\r'
+ '[' -s $'/Users/william.reilly/.nvm\r/nvm.sh' ']'
+ '[' -s $'/Users/william.reilly/.nvm\r/bash_completion' ']'
+ $'\r'
: command not found
+ $'\r'
: command not found
+ $'\r'
: command not found
...


http://www.rapidtables.com/convert/number/ascii-to-hex.htm

$ hexdump .bash_profile
(partial bit)

.nvm"
[

2e 6e 76 6d 22 0a 5b <<< As converted by online converter
2e 6e 76 6d 22 0d 0a 5b <<< MY TEXT FILE from Install Script has extra "0d"


re: 0a, 0d, 0d 0a

Test file contents: (Made with TextMate "Line Ending" options: LF, CR, CRLF)


line 1
line 2


$ hexdump .bash_profile_LF <<< 0a
0000000 6c 69 6e 65 20 31 0a 6c 69 6e 65 20 32 0a

$ hexdump .bash_profile_CRMacClassic <<< 0d
0000000 6c 69 6e 65 20 31 0d 6c 69 6e 65 20 32 0d

$ hexdump .bash_profile_CRLFWindows <<<< 0d 0a
0000000 6c 69 6e 65 20 31 0d 0a 6c 69 6e 65 20 32 0d 0a


@wreilly would you mind filing a new issue? comments posted on old, closed issues are pretty hard for maintainers to locate and fix.

export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

I just add codes above to .bash_profile, and it works.

Maybe this will help someone, as it took me quite a while to completely figure out. I am using Linux Mint, and other systems may be the same.
Installation of nvm went fine, but nvm would never be available in a new bash terminal window until I manually entered the two lines:

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

This was odd, because these two lines were already there, at the end of the initialization file "~/.profile".
The explanation is that bash uses a different chain of initialization files depending on whether it is being started as a login shell or non-login. This is spelled out in man bash, but rather cryptic as to how to tell.
The way to tell is type "echo $0" at the terminal prompt. If the response is "-bash" if it's a login shell, "bash" if not.
The shells I was getting from Ctrl-Alt-T were non-login, and so the system was looking for

~/.bashrc

instead of

~/.profile

But there was no such file. After I created it and put the initialization lines in it, now I get nvm available in every new terminal window, like I want.
Once you know whether you have login or non-login shells, you can consult man bash to decide where you want to put your initialization. The priority of the files is explained near the beginning of the documentation.
Another detail, which is of course obvious once you know, is that the nomenclature "~/.bashrc" means the file ".bashrc" in the home folder of the current user. So, for user "guest", the literal path would be "/home/guest/.bashrc". And, since the filename starts with a dot, it is a hidden file that won't normally show up. To see it in a GUI, you would need to do something like View > Show Hidden Files. To see it in a terminal window, you would enter "ls -a" at the prompt.

I had a similar problem as https://github.com/creationix/nvm/issues/576#issuecomment-354889388. I use the Fish shell so I switch to bash by typing bash. That means it's not a login shell, and therefore .bash_profile wasn't respected. Putting

export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

into .bashrc (not .bash_profile) solved it for me.

hi experts ,
I am facing issue in installation please help

$ nvm install node
Local cache found: $NVM_DIR/.cache/src/node-v9.4.0/node-v9.4.0.tar.gz
Checksums match! Using existing downloaded archive $NVM_DIR/.cache/src/node-v9.4.0/node-v9.4.0.tar.gz
$>./configure --prefix=/c/Users/Sumit/.nvm/versions/node/v9.4.0 <
which: no python2.7 in (/c/Users/Sumit/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Sumit/bin:/c/ProgramData/Oracle/Java/javapath:/g/app/sumittech/product/12.2.0/dbhome_1/bin:/c/Program Files (x86)/Intel/iCLS Client:/c/Program Files/Intel/iCLS Client:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/c/Program Files/Java/jre-9.0.1/bin:/c/Program Files/nodejs:/c/Program Files (x86)/Yarn/bin:/c/Program Files (x86)/Windows Kits/8.1/Windows Performance Toolkit:/c/Users/Sumit/scoop/apps/nodejs/current/bin:/c/Users/Sumit/scoop/apps/nodejs/current:/c/Users/Sumit/scoop/apps/yarn/current/Yarn/bin:/c/Users/Sumit/scoop/apps/yarn/current/bin:/c/Users/Sumit/scoop/shims:/c/Users/Sumit/AppData/Local/Microsoft/WindowsApps:/c/Users/Sumit/AppData/Roaming/npm:/c/Users/Sumit/AppData/Local/Yarn/bin:/usr/bin/vendor_perl:/usr/bin/core_perl)
which: no python2 in (/c/Users/Sumit/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Sumit/bin:/c/ProgramData/Oracle/Java/javapath:/g/app/sumittech/product/12.2.0/dbhome_1/bin:/c/Program Files (x86)/Intel/iCLS Client:/c/Program Files/Intel/iCLS Client:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/c/Program Files/Java/jre-9.0.1/bin:/c/Program Files/nodejs:/c/Program Files (x86)/Yarn/bin:/c/Program Files (x86)/Windows Kits/8.1/Windows Performance Toolkit:/c/Users/Sumit/scoop/apps/nodejs/current/bin:/c/Users/Sumit/scoop/apps/nodejs/current:/c/Users/Sumit/scoop/apps/yarn/current/Yarn/bin:/c/Users/Sumit/scoop/apps/yarn/current/bin:/c/Users/Sumit/scoop/shims:/c/Users/Sumit/AppData/Local/Microsoft/WindowsApps:/c/Users/Sumit/AppData/Roaming/npm:/c/Users/Sumit/AppData/Local/Yarn/bin:/usr/bin/vendor_perl:/usr/bin/core_perl)
./configure: line 3: exec: python: not found
nvm: install v9.4.0 failed!

regards
Sumit

@KUMARSUMIT585 would you please file a separate issue for that? (Regardless, python is required to compile node)

Hi, I just installed nvm like the original posted stated and I am getting the same issues. I went to the github (https://github.com/creationix/nvm) and copied in the curl command:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

I then restarted my terminal session (closed and opened new window as well as quit terminal and restarted it).

I am unable to use nvm I get:

-bash: nvm: command not found

This happens on both my Mac Pro and my Macbook Pro both running 10.13.2. I am following a video of node.js development and the video author does not have these problems: after install nvm commands work.

My $PATH is "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" and I've searched for both ~/.bashrc and ~/.bash_profile but I don't seem to have either of these files. Hopefully this is a simple issue and thanks in advance!

@jbburf ah, if you don't have either of those files, you'll have to manually create one (on a mac, you probably want ~/.bash_profile)

Thanks @ljharb, if I create ~/.bash_profile and re-run the install it works. This would be a great thing to add to the installer.

@jbburf Creating bash_profile is a bit intrusive, so the installer is intentionally not doing that. However, it'd be great to add a PR with those instructions to the install script (on Mac), if you're open to submitting one :-D

Just to mention what my issue ended up being:

~/.bashrc and ~/.bash_profile were both _not_ being executed on my Mac (running 10.11.6). I had to add the following code into ~/.profile to make it work (the installer would not do this):

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

Not sure why it has to be one and not the others but perhaps if the installer could detect this it could write to the correct file?

Hey, everyone. I'm trying to install NVM on My Mac (running OSX Yosemite 10.10.5).

I was using Node with Homebrew, but I found it difficult to manage Node with it so I uninstalled it and decided to go with NVM.

I did so by running these commands:

brew uninstall node
brew uninstall --force node

Now that Node is uninstalled via Homebrew, I went to try to install NVM via cURL.

I ran the cURL install script:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

I then tried to install the latest version of Node using:

nvm install node

I then got the "command not found" error:

-bash: nvm: command not found

I tried to resolve by re-running the cURL command and got this excerpt from the output (entire output excluded for brevity):

nvm source string already in /Users/Matthew/.bashrc

This implies that NVM has successfully been installed, correct?

As advised by the README, I restarted Terminal. Again, I got the same "command not found" error.

Additionally, as advised by the README, I checked to see if I have a .bash_profile file. I checked by running:

cat ~/.bash_profile

This provided the following output:

source ~/.profile

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

The README says to add source ~/.bashrc to the file. I can edit the file via Nano; however, I am conflicted. Will adding source ~/.bashrc to .bash_profile conflict with the already included source ~/.profile?

Thank you for the help!

@MatthewKosloski it shouldn't conflict; but another alternative is copying the nvm-related lines from your bashrc into your .profile.

@ljharb Editing the ~/.bash_profile file resolved the issue. Thanks for the fast reply!

Hey guys, I'm running into the "-bash: -v: command not found" issue after installing nvm. I have run through a bunch of the solutions that seemed to have worked for other people above, but nothing is working for me.

I am running MacOS 10.13.4, and it appears that NVM finishes installation after running the terminal command: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

However, I then try to confirm the installation with "-v nvm" and I get the "command not found" result.

I do have a .bash_profile, and here are the contents:

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

I tried adding

export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh

to the bottom of the .bash_profile file, but it did not fix the problem.

Thanks in advance for any help you can provide.

@deelydian could you file a new issue for that?

@ljharb No problem at all...I just submitted a new issue. Sorry if my original comment was out of place here. And thank you very much for the response!

I had a similar issue using Capistrano to run npm commands (using nvm). My .bashrc file had the following right at the top,

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

which was causing me issues when running the capistrano commands. I solved this my moving the export NVM_DIR... above this case.

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
source $NVM_DIR/nvm.sh

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

For anyone wanting a specific version of node as default

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

# use node v9 becuase v10 is not supported by many projects
nvm alias default 9

In my case it was a lack of the execute mode on the shell script. Calling
chmod 755 ~/.nvm/nvm.sh
fixed the issue.

[[ -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#

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

source ~/.bash_profile

That fixed the issue.

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

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.

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.

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.

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

What shell are you using?

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.

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?

@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.

@kristjankoppel thank you too much

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

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

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

@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 ?

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

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.

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

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"'

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.

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

@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.

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

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:

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.

如果在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".

如果在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

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!

如果在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

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.

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

[[ -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#

this works for me,thank you!

I use oh my zsh, then I must add this lines:

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

At the end of the .zshrc file. It works for me

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

Perfectly solved my problem, thank you!

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"'

The same problem has came to me, and fortunately it was solved with your method, thanks!

If you use zsh, simply do this:

go to your .zshrc file, in your terminal: vi ~/.zshrc then press i, then use right arrow to go to the end of the file, then press enter for a new line.
After that, copy this:
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVM
paste it in .zshrc
Then, hit ESC then type :wq then hit enter. Should work now

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

This worked for me. I didn't have a .zshrc file so I created one and followed the instructions here. It worked when I did

I have a docker container pulling node:alpine which doesn't come with bash. I install bash, but the .bash_profile and .bash_rc don't exist, maybe that is something that should be checked during install and if they don't exist create them?

You don't need to use bash; any posix shell will work, and afaik all of them have a profile file.

It's a known issue that profile file detection is hard, and if you have a shell but no relevant profile files, it's very hard to detect that.

Hello, via this article I started the installation of my pimp with Catalina. To make nvm work, you have to copy/paste these 2 lines of code in your .bash_profile and in .bashrc these 2 lines and finally, this code in your .zshrc

.bash_profile

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

.bashrc

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

.zshrc

source ~/.nvm/nvm.sh

Caused by failure of custom environment variables after installing zsh
vi .zshrc
Addsource ~ / .bash_profile on the last line
Every time you start zsh, the environment variables are compiled, so you don't need to define it repeatedly in .zshrc

安装zsh后自定义环境变量失效导致的
vi .zshrc
在最后一行添加 source ~/.bash_profile
每次启动zsh都会编译环境变量,不用在.zshrc中重复定义

Hi, in WSL2 with Ubuntu 20.04 and zsh only i have to add:

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

And its works.

For my case, it was a permissions issue with the license! I needed to download the Developer Command Line tools from Apple (not the whole XCode) – and _accept the license_ – then, with all these solutions, it worked like a charm.

Link for Command Line License Download: https://developer.apple.com/download/more/

Was this page helpful?
0 / 5 - 0 ratings