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 · 182 comments
Closed

-bash: nvm: command not found #576

apaternite opened this issue Nov 12, 2014 · 182 comments

Comments

@apaternite
Copy link

@apaternite apaternite 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
Copy link
Member

@ljharb ljharb 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
Copy link
Member

@ljharb ljharb commented Nov 22, 2014

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

@ljharb ljharb closed this Nov 22, 2014
@alfredbez
Copy link

@alfredbez alfredbez 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
Copy link
Member

@ljharb ljharb 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
Copy link

@am11 am11 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
Copy link

@jeancdc jeancdc 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
Copy link
Member

@ljharb ljharb 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
Copy link

@jeancdc jeancdc 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
Copy link
Member

@ljharb ljharb 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
Copy link
Member

@ljharb ljharb commented Apr 4, 2015

@jeancdc does that fix your issue?

@jeancdc
Copy link

@jeancdc jeancdc commented Apr 5, 2015

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

@jeancdc
Copy link

@jeancdc jeancdc 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
Copy link
Member

@ljharb ljharb 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
Copy link

@jeancdc jeancdc commented Apr 5, 2015

I use Mac OS X 10.10.2 Yosemite

@ljharb
Copy link
Member

@ljharb ljharb 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
Copy link

@jeancdc jeancdc commented Apr 5, 2015

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

@ljharb
Copy link
Member

@ljharb ljharb 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
Copy link

@jeancdc jeancdc 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
Copy link
Member

@ljharb ljharb 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
Copy link

@jeancdc jeancdc 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
Copy link
Member

@ljharb ljharb commented Apr 5, 2015

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

@jeancdc
Copy link

@jeancdc jeancdc commented Apr 5, 2015

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

@ljharb
Copy link
Member

@ljharb ljharb commented Apr 5, 2015

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

@wonderdogone
Copy link

@wonderdogone wonderdogone 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
Copy link

@ysk8 ysk8 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
Copy link
Member

@ljharb ljharb 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
Copy link

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

@anivle
Copy link

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

@lwl0812
Copy link

@lwl0812 lwl0812 commented Jun 3, 2019

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

@tapion
Copy link

@tapion tapion commented Jul 18, 2019

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

@sanm1992
Copy link

@sanm1992 sanm1992 commented Jul 19, 2019

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

Perfectly solved my problem, thank you!

@LuluChina
Copy link

@LuluChina LuluChina commented Aug 20, 2019

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!

@Omar-Aziz
Copy link

@Omar-Aziz Omar-Aziz commented Aug 31, 2019

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

@chialuka
Copy link

@chialuka chialuka commented Nov 26, 2019

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

@thenetimp
Copy link

@thenetimp thenetimp commented Dec 20, 2019

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?

@ljharb
Copy link
Member

@ljharb ljharb commented Dec 20, 2019

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.

@matteobz
Copy link

@matteobz matteobz commented Feb 24, 2020

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

@PetelZhang
Copy link

@PetelZhang PetelZhang commented Mar 18, 2020

Caused by failure of custom environment variables after installing zsh
vi .zshrc
Add source ~ / .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中重复定义

@juliolv
Copy link

@juliolv juliolv commented May 16, 2020

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 it works.

@karmayoga-online
Copy link

@karmayoga-online karmayoga-online commented Aug 13, 2020

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/

@vikramvi
Copy link

@vikramvi vikramvi commented Mar 15, 2021

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

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

After this close terminal and open it again before banging your head on wall

@beyrerdn
Copy link

@beyrerdn beyrerdn commented Mar 23, 2021

nvm automatically put the following lines in .bashrc and I was getting the -bash: nvm: command not found error.

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_completionexport NVM_DIR=~/.nvm

I moved these lines to .bash_profile and it started working.

@shunyue1320
Copy link

@shunyue1320 shunyue1320 commented Apr 29, 2021

将~/.bashrc 复制到 ~/.bash_profile

重启终端

nvm -v
0.38.0

成功解决

@kumailZaidi12
Copy link

@kumailZaidi12 kumailZaidi12 commented May 18, 2021

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
after adding this to .bash_profile
run this command:
source .bash_profile
and now check nvm --version

@blazestudios23

This comment was marked as disruptive content.

@ljharb

This comment has been hidden.

@blazestudios23
Copy link

@blazestudios23 blazestudios23 commented Jun 18, 2021

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

This still works.

@blazestudios23
Copy link

@blazestudios23 blazestudios23 commented Jun 18, 2021

@blazestudios23 the hostility is unwarranted and unhelpful.

I'm not trying to be hostile, this issue has been open for 7 years, I'm honestly supposed that there hasn't been a solution in that time.

@ljharb
Copy link
Member

@ljharb ljharb commented Jun 18, 2021

@blazestudios23 no, the issue has been closed for 6 years. This (very long) thread contains a half dozen different problems, all of which are solved if you take the time to read the entire thread.

If you're still having a problem, please file a new issue. Commenting on this long and old one isn't going to help get anything solved.

@blazestudios23

This comment has been hidden.

@ljharb

This comment has been hidden.

@blazestudios23

This comment has been hidden.

@alderete-sfdc
Copy link

@alderete-sfdc alderete-sfdc commented Aug 19, 2021

Something to be aware of, which tripped me up for an hour, is that nvm is "Implemented as a POSIX-compliant function", as it states at the top of the nvm.sh script file. This means there's no nvm file in your path, and thus you can't verify that nvm is present using the which command. Instead, use nvm --version, and verify that you get expected output.

malderete-ltm:~ malderete$ nvm --version
0.38.0
malderete-ltm:~ malderete$ which nvm
malderete-ltm:~ malderete$ which node
malderete-ltm:~ malderete$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v14.17.5...
Downloading https://nodejs.org/dist/v14.17.5/node-v14.17.5-darwin-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v14.17.5 (npm v6.14.14)
Creating default alias: default -> lts/* (-> v14.17.5)
malderete-ltm:~ malderete$ nvm use --lts
Now using node v14.17.5 (npm v6.14.14)
malderete-ltm:~ malderete$ which node
/Users/malderete/.nvm/versions/node/v14.17.5/bin/node

(As someone who is only semi-command line literate, I lean on the which command by muscle memory. Using nvm --version is in the instructions, but if you're an idiot like me, you might miss/skip over that part, and use which nvm by reflex, and think that nvm isn't installed.)

@ljharb
Copy link
Member

@ljharb ljharb commented Aug 19, 2021

@alderete-sfdc command -v nvm is explicitly mentioned in the readme: https://github.com/nvm-sh/nvm#troubleshooting-on-linux

@alderete-sfdc
Copy link

@alderete-sfdc alderete-sfdc commented Aug 19, 2021

@ljharb Oh, yes, it's mentioned in a couple places. Quite clearly!

I'm just making a quick note for people like me, who know just enough to think they can skip the "easy" parts of the docs. When I finally noticed the difference, the part I'd been skipping, I groaned out loud and metaphorically head-desked. (As a "professional" technical writer, it's especially embarrassing.)

Just posting a quick note, in case there are others who might be doing the same thing. (Since, as you pointed out in an relatively recent comment, this issue has been closed for years, and yet people are still somehow having problems. Mine was that I was being an idiot.) I hope it's viewed as constructive, not a complaint—that's certainly my intent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet