DEV Community

Bhavesh Kasturi
Bhavesh Kasturi

Posted on • Updated on

nvm command not found :(

Node Version Manager (NVM) is a tool used to manage multiple active Node.js versions.

If you're trying to install NVM(Node Version Manager) in WSL you probably may run into this error.

-bash: nvm: command not found
Enter fullscreen mode Exit fullscreen mode

What is WSL ?

The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.

How to fix this error ?

  • Installation

To install nvm use the following cURL or Wget command

bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  • nvm command not found :(

Running either of the above commands downloads a script and runs it, but if you type nvm and if you get bash: nvm: command not found it happens because the source is missing from the following profile files

~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc
Enter fullscreen mode Exit fullscreen mode


To fix this simply follow these steps.

  • Steps

1) Type the following command.

nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

2) Add the source lines from the snippet below to the correct profile file at the bottom.

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
Enter fullscreen mode Exit fullscreen mode

3) Close and restart the terminal it should fix the error!

The official documentation on GitHub is really helpful.

Thanks for reading!

Top comments (22)

Collapse
 
gabrielduete profile image
Gabriel Duete

Thanks!! /o/

Collapse
 
bossfelfo profile image
fbf.dev

This was really helpful, though in my case - I had to nano ~/.bash_profile and added the code snippet

Collapse
 
ridhikgovind profile image
Ridhik Govind

This worked like a charm. Thanks a lot !

Collapse
 
piyush_bhatee_3a089290946 profile image
Piyush Bhatee

Thanks Bro

Collapse
 
mariafeli profile image
Maria

After days of trying different solutions, THIS ONE WORKS !!! THANK YOU

Collapse
 
rinsama77 profile image
imrinzzzz

Than you!!! I downloaded oh-my-zsh and it replaced my previous .zshrc file. This helps a lot TT.

Collapse
 
duhbhavesh profile image
Bhavesh Kasturi

Glad It helped! :)

Collapse
 
viktor_k profile image
Viktor Kushniruk

I wish I had read your comment before following the article...

Collapse
 
isabelalima profile image
Isabela Lima

Thank you, this helped a lot!

Collapse
 
samboosa5k profile image
samboosa5k

thank you! :D

Collapse
 
herison profile image
Herison S.

Obrigadoooooooo

Collapse
 
gsingh profile image
G.Singh

Thank you good Sir.