692

I am trying to install NVM as per these instructions

I typed in this command in terminal:

$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh

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

$ nvm install 0.8

but I get the response:

-bash: nvm: command not found

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

Additional Info:

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

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

but this times out every time I attempt that.

John Smith
  • 7,243
  • 6
  • 49
  • 61
jordan
  • 9,570
  • 9
  • 43
  • 78

36 Answers36

1653

I think you missed this step:

source ~/.nvm/nvm.sh

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

https://github.com/creationix/nvm

John Smith
  • 7,243
  • 6
  • 49
  • 61
Deepak Lamichhane
  • 19,076
  • 4
  • 30
  • 42
  • 21
    Let's make the documentation better. I've created an issue on the nvm repo: https://github.com/creationix/nvm/issues/748 – Jonny Burger May 06 '15 at 09:17
  • 5
    I executed this manually multiple times until I finally put it in my .bashrc! – Brady Dowling Jul 21 '15 at 22:05
  • 4
    this worked for me but in order to automate it i had to create profile first. "touch ~/.profile", "open ~/.profile" , paste above, save+ close. works in new windows now – Sonic Soul Jun 04 '16 at 15:47
  • `nvm`, `node`, and `npm` where working without this. Now, for some reason, I have to do this or those commands aren't found. Why wasn't this necessary before but is now? – tjfwalker Oct 28 '16 at 18:32
  • 22
    Adding it to `~/.bash_profile` was what worked for me – spencer.sm Jul 23 '17 at 05:50
  • 2
    This was the missing line that worked for me.. I spent hours trying to figure out how to fix the permission errors i was getting when trying to deploy my firebase cloud function.. if you're stuck on permission errors - id suggest uninstalling node and then re installing the nvm - AND don't forget this line of code you'll need it.. thanks... - site that helped me uninstall it - https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/ – Coding while Loading Jul 13 '19 at 16:19
  • 40
    This worked for me. I added `source ~/.nvm/nvm.sh` to my `~/.zshrc` and now `nvm` works every time – Eddy Vinck Jul 19 '19 at 08:18
  • 1
    I tried this, but for some reason when reopening a bash, I had the same problem. I did what the following link suggests: https://github.com/nvm-sh/nvm/issues/2060 and it worked well for me. I hope this could help. Thx – fablexis Jun 08 '20 at 17:27
  • I would assume this to run itself after the installation?? This is so weird but thank you for saving tons of time looking for other tweaks! – Yashank Oct 07 '20 at 22:49
  • The docs for installing NodeJS on WSL2 don't mention anything about this command, but that command worked for me. Thank you! https://learn.microsoft.com/en-us/windows/nodejs/setup-on-wsl2 – tlochner95 Feb 05 '21 at 17:20
  • OMG! This is crazy! In the GIT install instructions, there's no mention of this source. It took me days to resolve docker dependencies, while the actual problem was THIS source! Thank YOU!!! – GTodorov Sep 13 '21 at 22:14
  • In my case, the folder ~/.nvm/ did not contain any files, so i put nvm.sh in there and now everything is working – JrBriones Feb 01 '22 at 21:43
  • reinstall brew right after this `brew reinstall nvm` – Rolando Niubó Feb 18 '22 at 18:57
  • This must be marked as unswer – Profesor08 Jul 26 '23 at 16:17
  • If someone get stuck, how to & where to create these files `/.bashrc or ~/.profile or ~/.zshrc` to them, just create a file `touch ~/.profile` then to edit the file in console `nano ~/.profile` or you can edit the file manually from this directory `C:\Users\` and then paste `source ~/.nvm/nvm.sh` save the file. It worked for me. – Sabbir Sobhani Aug 13 '23 at 10:22
624

Check your .bash_profile, .zshrc, or .profile file. You most likely had a problem during the installation.

You should have the following at the end of one of those files.

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

The . $HOME/.nvm/nvm.sh is the same as source $HOME/.nvm/nvm.sh

See: Sourcing a File

You can also check to see if you have a .nvm folder.

ls -a | grep .nvm

If you're missing that folder then the installation failed to run the git command. This could be due to being behind a proxy. Try running the following instead.

git clone http://github.com/creationix/nvm.git .nvm
johndpope
  • 5,035
  • 2
  • 41
  • 43
travis
  • 8,055
  • 1
  • 17
  • 19
  • I do have that line at the end of my .bash_profile file. But I am missing the .nvm file. I'm guessing the missing file is the problem? – jordan Jun 03 '13 at 21:15
  • 2
    The `.nvm` should be a directory. It's installed via the following command `git clone git://github.com/creationix/nvm.git $NVM_TARGET`. You said previously that you tried to run that command yourself and it failed? Most likely you are behind a proxy and are not configured probably. Try running the follow instead. `git clone http://github.com/creationix/nvm.git .nvm` – travis Jun 03 '13 at 22:00
  • Looks like I do have the .nvm directory. I also have the needed line in the .bash_profile file. – jordan Jun 04 '13 at 04:18
  • 43
    also have the line, but 'source ~/.nvm/nvm.sh' works – basickarl Mar 21 '15 at 12:22
  • 2
    If the .nvm folder is empty it's probably because fetching of the repo has failed due to xcode agreement license not been accepted. Running `sudo xcodebuild -license` and accepting the license (by pushing `space` for reaching the end of the license and to agree to its terms) does the trick. – Pierre Criulanscy Oct 05 '15 at 12:07
  • 4
    You may also need to `source .bashrc` or `source .profile` depending – Henry Tseng Feb 06 '16 at 16:32
  • Where and how do I find the file .bash_profile or .profile? – Niahc Jan 20 '17 at 22:48
  • 1
    Almost always those files will exists in your home dir. `source $HOME/.bashrc`, etc. – travis Feb 04 '17 at 20:18
  • 9
    put nvm configs in `.zshrc` help me to solve it. thanks – Pedro Soares Mar 07 '20 at 13:53
  • Nothing but `.zshrc` worked for me. – Cody Oct 25 '21 at 20:01
  • I also had to change the [ -z "$PS1" ] && return to [ "$CI" == "true" ] || ( [ -z "$PS1" ] && return ) line to make the .bashrc work in case it is launched in gitlab CI environment – Darth Jurassic Dec 27 '21 at 06:56
  • I restarted bash before trying this solution, and it worked! – Marlond25 Jun 05 '22 at 17:32
226

This works for me:

  1. Before installing nvm, run this in terminal: touch ~/.bash_profile

  2. After, run this in terminal:
    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash

  3. Important... - DO NOT forget to Restart your terminal OR use command source ~/.nvm/nvm.sh (this will refresh the available commands in your system path).

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

Alireza
  • 100,211
  • 27
  • 269
  • 172
111

Quick answer

Figure out the following:

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

Example

As you can see it states zsh and not bash. enter image description here

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

Why does this happen

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

In other words: this is NVMs fault.

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

Quick answer for zsh users

curl raw.github.com/creationix/nvm/master/install.sh | zsh
basickarl
  • 37,187
  • 64
  • 214
  • 335
82

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

user2015258
  • 1,287
  • 10
  • 5
45

All answers to this questions are useful. Especially the answer given by Travis helped me. For Mac OS X users I would like to provide some steps which will help them to work with the fresh installation of Node Version Manager a.k.a. nvm.

Installing & using nvm on Mac OS X

Here are the steps for fresh installation of nvm and using it without any issue:

  • Install homebrew from here.
  • Using homebrew install nvm

    brew update brew install nvm

  • Create .nvm directory at ~/.nvm location.

    mkdir ~/.nvm

  • Now if you don't have .bash_profile file setup for OS X terminal then please create a .bash_profile at the root level:

    nano ~/.bash_profile

  • Paste below code in the .bash_profile and press CTRL + O and press enter to save .bash_profile file. Press CTRL + X to exit from editor:

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

  • Now either quite (CMD + Q) the terminal or run below command to load .bash_profile settings:

    source ~/.bash_profile

  • Now run nvm ls command to get the list of all installed nodejs versions.

S.Mishra
  • 3,394
  • 28
  • 20
33

I faced a similar issue when installing nvm on a MacBook Pro.

I had installed nvm initially using brew:

brew install nvm

But when I run the command:

nvm --version

I get the error:

zsh nvm: command not found

Here's how I fixed it:

Installing nvm using brew is not enough to get it to work. You also need to do the following below;

  • Confirm that the source ~/.zshrc, ~/.bash_profile, ~/.profile, or ~/.bashrc file exists:

    zsh: ~/.zshrc
    
    bash: ~/.bashrc
    
    ksh: ~/.profile
    

    Else create it using:

    touch ~/.zshrc
    
    touch ~/.bashrc
    
    touch ~/.profile
    
  • Next, run either of the commands below:

    Note: You can check the referenced link below to get the updated commands.

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

    OR

    wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
    

    Note: Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc)

    export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm.
    

You can check the referenced link below to get the updated script.

Reference: Installing and Updating NVM

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
29

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

After that, add these lines

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

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

hd84335
  • 8,815
  • 5
  • 34
  • 45
27

Assuming that you have installed nvm using brew (I am on a mac), I mean something like brew install nvm, all you need to do is:

 1. You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

 2. Add the following to ~/.zshrc or your desired shell configuration
    file:

      export NVM_DIR="$HOME/.nvm"
      [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
      [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion
Capfer
  • 829
  • 9
  • 22
23

Same problem encountered. You have to source shell file as well as change nvm's default version.

First, source ~/.nvm/nvm.sh.

Second, change nvm's default version.

nvm alias default 16.14.2

If you don't change nvm's default version, you will find the node version stay the same when you switch to another iTerm tab.

magentaqin
  • 1,949
  • 13
  • 10
  • Thanks, this was helpful and fixed my issue. I didn't have to check the default version though as I didn't have it. default -> 16.14.2 (-> N/A) – Yvan Rugwe Jul 27 '22 at 10:06
21

OSX 10.15.0 Catalina (released November 2019) changed the default shell to zsh.

The default shell was previously bash.

The installation command given on the nvm GitHub page needs to be tweaked to include "zsh" at the end.

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | zsh

Note: you might need to ensure the .rc file for zsh is present beforehand:

touch ~/.zsrhrc
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
  • 1
    Just a small correction as I was initially tripped up by the file name. It's `touch ~/.zshrc` :) Otherwise can verify the above works – jjkl Jul 15 '20 at 22:22
  • Adding the .zsrhrc even works with Homebrew. It's in the README.md file under the Troubleshooting on macOS – Konkret Jul 05 '21 at 16:42
21

I have the same problem and what saved my life is the sentence "you may have to add to more than one of your "~/.bashrc, ~/.profile, or ~/.zshrc files". the following lines were in my .bashrc only, I added it to files ".bash_profile" and ".profile" and worked for me .

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
tananyGeek
  • 429
  • 4
  • 4
  • I tried this and even created the .profile with no luck. – Urasquirrel Nov 19 '20 at 20:32
  • 2
    agh! I just had to restart the terminal! Thanks! – Urasquirrel Nov 19 '20 at 20:35
  • 4
    Yes, restart the terminal or run the following in the corresponding shell: bash: `source ~/.bashrc` zsh: `source ~/.zshrc` ksh: `. ~/.profile` – Justin.Mathew Dec 10 '21 at 17:39
  • 1
    After a lot of research on this for days. Finally only this worked for me!. I had this only on .zshrc before. After adding it in all the other files mentioned by @ahmdGeek It started running. Thanks a lot. – Joshua Jan 31 '23 at 14:04
16

First add following lines in ~/.bashrc file

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 open terminal and source the nvm.sh script

source ~/.nvm/nvm.sh
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
11

For MacOS;

Run on Terminal >

open ~/.bash_profile

Paste all of this=

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Yunus ER
  • 1,999
  • 2
  • 9
  • 14
8

For Mac OS:

  1. Open Terminal
  2. Run touch ~/.bash_profile
  3. Run vi ~/.bash_profile
  4. Type source ~/.nvm/nvm.sh
  5. Press Shift + Esc and type wq and press enter
  6. Done.
Arjun Kesava
  • 740
  • 1
  • 10
  • 14
8
  1. Open terminal
  2. if you have zsh terminal then type command 'open ~/.zshrc'
  3. Add end of file and save the following: source ~/.nvm/nvm.sh
Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
7

Over time, nvm (from homebrew) changed its post-installation instructions.

I was getting nvm_find_nvmrc not found on a new computer, until I replaced

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

with

[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

which properly found the installation location.

chaqke
  • 1,497
  • 17
  • 23
6

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

Create the profile file

touch ~/.bash_profile

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

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

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

.  ~/.bash_profile
patridge
  • 26,385
  • 18
  • 89
  • 135
nicbou
  • 1,047
  • 11
  • 16
6

Not directly connected to the question, but there is a similar problem that may happen, take a look at this question: Can't execute nvm from new bash


Here's my answer on that post, just for the reference:

If you are running from a new bash instance, and you HAVE the initialization code at your ~/.bashrc, ~/.bash_profile, etc, then you need to check this initialization file for conditionals.

On Ubuntu 14, there is a:

case $- in
    *i*) ;;
      *) return;;
esac

At line 6, that will halt it's execution if bash is not being ran with the "-i" (interactive) flag. So you would need to run:

bash -i

Also, at the end of the file, there is a

[ -z "$PS1" ] && return

That will halt it's execution if not being ran with $PS1 set (like on a remote ssh session).

If you do not wish to add any env vars or flags, you will need to remove those conditionals from your initialization file.

Hope that's helpful.

Community
  • 1
  • 1
Alan Sikora
  • 497
  • 5
  • 11
6

For Mac OS:

  1. Open Terminal
  2. Check if you have .profile file with this command:

ls -a ~/

  1. If you havnt this file just create one:

touch ~/.profile

  1. Add this command to .profile file :

source ~/.nvm/nvm.sh

  1. Press Shift + Esc and type wq and press enter
tn2000
  • 642
  • 1
  • 8
  • 13
5

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

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

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

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

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

vantony
  • 513
  • 6
  • 9
5

For the issue was fixed when I moved

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

to the end of .zshrc

almeynman
  • 7,088
  • 3
  • 23
  • 37
2

I had fixed this problem.

  1. touch ~/.bash_profile
  2. open ~/.bash_profile
  3. pasteexport NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
2

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

nvm install 8.3.0 bash: nvm: command not found windows

So, follow or verify below following steps-

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

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

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

Now run Git Bash as Administrator and then.

$ nvm install 8.3.0 all

Downloading node.js version 8.3.0 (64-bit)...
Complete
Creating C:\Users\Administrator\nvm\temp

Downloading npm version 5.3.0... Complete
Installing npm v5.3.0...

Installation complete. If you want to use this version, type

nvm use 8.3.0

$ nvm use 8.3.0
Now using node v8.3.0 (64-bit)

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

$ nvm --version
Running version 1.1.5.

Usage:
-----------------------

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

ArifMustafa
  • 4,617
  • 5
  • 40
  • 48
2

Had the same problem, but this worked for me:

Since macOS 10.15, the default shell is zsh and nvm will look for .zshrc to update, none is installed by default. Create one with touch ~/.zshrc and run the install script again.

more info here: Troubleshooting on macOS

Bekzat
  • 170
  • 1
  • 6
1

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

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

# if nvm dir is not set and the standard nvm directory exists
if [ -z "$NVM_DIR" -a -d "$HOME/.nvm" ] ; then
# set nvm dir
  export NVM_DIR="$HOME/.nvm"
fi

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

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

Warren MacEvoy
  • 898
  • 9
  • 14
1

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

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

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

priyankvex
  • 5,760
  • 5
  • 28
  • 44
1

On Debian, as well as adding the below lines to my .bash_profile as one of the above answers said. I also had to open up my terminal preferences (Edit -> Profile Preferences -> Command) and enable 'Run command as a login shell' to get it to work.

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

Edit: For those on Mac be aware that macOS doesn't read .bashrc on Terminal start, so using .bash_profile is preferable. See Here.

tomhughes
  • 4,597
  • 2
  • 24
  • 33
1

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

JerryZhou
  • 4,566
  • 3
  • 37
  • 60
1

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

Alderete
  • 452
  • 4
  • 5
  • I can't believe I'm your first upvote... `which` is also my go-to for determining if I have something... Can't believe it failed me. – Robert Oct 20 '21 at 15:08
1

After spending more than 3 hours testing some of the solutions above I came across an answer that was working for me. I am under Ubuntu 20.04.3 LTS and with a fresh install added the official command:

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

The problem was that my version of curl was obtained via snap. Removing it and re-installing it as suggested by this answer fixed the issue:

sudo snap remove curl
sudo apt install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh 
| bash
nvm install node
CyberMessiah
  • 1,084
  • 11
  • 14
0

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

Vishnu Dubey
  • 141
  • 1
  • 3
  • 10
0

Use following codes

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash`
source ~/.nvm/nvm.sh`
nvm install 0.8
Vivekanand Panda
  • 832
  • 12
  • 23
0

After trying multiple steps, not sure what was the problem in my case but running this helped:

touch ~/.bash_profile
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

Verified by nvm --version

nvm -v output

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
0

I'm using linux brew and bash and it asked me to add the following code to ~/.profile

export NVM_DIR="$HOME/.nvm"
  [ -s "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

But in my case, that did not work. Instead, adding it to ~/.bashrc worked.

Daya
  • 121
  • 1
  • 6
0

To overcome the above problem developer need install NVM in his machine to control the nodejs versions. For this we need to follow the below steps,

  1. All nodejs version has to be uninstalled from the system. Install Node version manager Download the Node Version Manager from the repository from Visit https://github.com/coreybutler/nvm-windows#installation--upgrades
  2. Install nvm-windows for windows and for other operating system find the available pack and install it.
  3. If the System is having Admin user then we need to install under Admin user only since nvm will modify Environment variable while installing NodeJS.
  4. While installing we have to be very careful about the installation folder.It should be under public folder not to any specific user. note : This is the one of the problem NVM could not load in the command prompt or power shell .if you installed NVM in the default location by the installer.
  5. Install a version of Nodejs by using the following command.
    nvm install node-version
    Example : nvm install 14.3.3

6.To see the versions of Nodejs you have installed on your machine
nvm list

  1. To use/load a specific version of Nodejs
    nvm use node-version
    example :nvm use 14.3.3