nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

-bash: nvm: command not found

apaternite opened this issue · comments

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?

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 (#576 (comment)) 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.

commented

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

commented

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

commented

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

commented

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?

commented

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

commented

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_completionin ~/.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.

commented

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.

commented

@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