Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NVM giving error while doing nvm ls

Tags:

node.js

nvm

I was trying to install and switch between node version, so i first install nvm using below

Administrators-MacBook-Pro:~ user.name$ sudo npm install nvm -g
Password:
npm http GET https://registry.npmjs.org/nvm
npm http 304 https://registry.npmjs.org/nvm
npm http GET https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/mkdirp
/usr/local/bin/nvm -> /usr/local/lib/node_modules/nvm/bin/nvm
[email protected] /usr/local/lib/node_modules/nvm
└── [email protected]

After this i was trying to do "nvm ls" to list node version but it gave me an error(below). Please advice what's wrong with it

Administrators-MacBook-Pro:~ user.name$ nvm ls

module.js:340
    throw err;
          ^
Error: Cannot find module '/usr/local/lib/node_modules/nvm/bin/nvm-ls'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/nvm/bin/nvm:15:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
like image 723
Amit Avatar asked Jul 16 '13 04:07

Amit


People also ask

How do I change NVM version?

Switching among Node. 7; we can simply run either nvm use 12.22. 7 or nvm use 16.13. 0 to easily switch into either version we need. Note that since we only have one version that begins with 12, 14, or 16, we can switch versions with a simple nvm use 16 , nvm use 14 , or nvm use 12 command.

What is the latest NVM version?

The latest version of nvm is 0.39. 0 , and it can be installed by curl or wget command: The script, install.sh , clones the nvm repository to ~/.

Do I need to uninstall Node to use NVM?

You can use it to install multiple versions of node, and then you can easily switch the currently used node version with one line of command. In other words, you don't need to uninstall and install anymore, just use nvm to install which version you want to use, and just switch with one instruction after installation!


4 Answers

I recently ran into this problem after I installed nvm as an npm package (from https://npmjs.org/package/nvm).

To resolve the issue, install nvm directly using the instructions at https://github.com/creationix/nvm#installation

Once installed and

source ~/.nvm/nvm.sh

ran (this is important, as it makes nvm available in your current terminal session), then you'll be able to run

nvm ls

and other nvm commands successfully from your project directory.

Hope this helps & cheers to learning node!

like image 188
jewel Avatar answered Sep 30 '22 07:09

jewel


To use the nvm command you need to source it as described above. But you don't want to do this after every login.

Just add these lines to your ~/.bashrc, ~/.profile, or ~/.zshrc file to have it automatically sourced upon login:

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

See also https://github.com/creationix/nvm#manual-install

like image 42
Sebastian Tilch Avatar answered Sep 30 '22 09:09

Sebastian Tilch


just to add, I use mac as well but non default shell (zsh) installing nvm will modify .bash_profile (and add line of "source ~/.nvm/nvm.sh")

so I was getting same error, you need to make sure you need to add "source ~/.nvm/nvm.sh" to your shell profile file (for me it was .zshrc)

like image 44
Greyeye Avatar answered Sep 30 '22 07:09

Greyeye


@jewel is correct: As of January 2016 (and maybe earlier), the NPM-installed version of nvm no longer seems to exist (at least, its github repo gives a 404). If this old, unmaintained package is installed, you may see errors like "local" not implemented yet or Error: Cannot find module './nvm-help' when typing nvm commands.

The correct version of nvm now comes from https://github.com/creationix/nvm

If you have installed the earlier (now unmaintained) version, you can get back on the air by doing these steps:

  1. npm uninstall -g nvm
  2. Using the Install Script on the github page above
like image 31
richb-hanover Avatar answered Sep 30 '22 09:09

richb-hanover