31

Following these instructions, I tried to install yeoman using npm twice: http://yeoman.io/learning/index.html

After the first failure, I uninstalled node using these instructions: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X) Then, I installed nvm and node/npm (via nvm) with one error:

[Yeoman Doctor] Uh oh, I found potential errors on your machine
---------------

[Error] NPM root value is not in your NODE_PATH
  [info]
    NODE_PATH = /Users/joanna/.nvm/v0.10.22/lib/node_modules:.
    NPM root  = /Users/joanna/.node/lib/node_modules

  [Fix] Append the NPM root value to your NODE_PATH variable
    Add this line to your .bashrc
      export NODE_PATH=$NODE_PATH:/Users/joanna/.node/lib/node_modules
    Or run this command
      echo "export NODE_PATH=$NODE_PATH:/Users/joanna/.node/lib/node_modules" >> ~/.bashrc && source ~/.bashrc

I pasted that command in, and then I ran npm install -g yo again.

After following the instructions from the yeoman site again, it still can't find yeoman. I receive this error: -bash: yo: command not found

What is wrong? The Yeoman Doctor says: "Everything looks alright!"

Community
  • 1
  • 1
Joanna Marsden
  • 503
  • 1
  • 4
  • 10

9 Answers9

23

All I needed to do was adding this line to .bash_profile

export PATH="$PATH":~/.node/bin

You can execute this to add it automatically:

printf "\nexport PATH=\"\$PATH\":%s\n" ~/.node/bin >> ~/.bash_profile

Tested on OS X 10.9, 10.10, 10.11 and Ubuntu 14.04

fregante
  • 23,010
  • 11
  • 97
  • 127
  • For me on OSX it was the following line: `export PATH=${PATH}:~/.node/bin` and don't forget to restart the prompt for the change to take action. – nilsi Feb 04 '15 at 15:15
  • @nilsi AFAIK it does the same thing; yours is just using a different string interpolation method – fregante Feb 04 '15 at 16:23
18

Short version:

In your shell, type the following commands:

  1. npm config set prefix ~/npm

  2. echo "export NODE_PATH=$NODE_PATH:/home/$USER/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc

  3. Then reinstall Yeoman:

    npm install -g yo

Then everything should work fine!

Explanation:

Had a similar condition, except yo command did work, but any installed generators didn't appear after installing them, this solved the issue.

The problem is that your npm path is set to /usr/local, which is a directory that requires root/sudo privileges, since yo is a user command, it shouldn't be ran as a superuser, and if you'll try to run sudo yo, Yeoman will tell you that explicitly.

I also tried to chown -R $USER:$USER /usr/local, and chmod -R /user/local +rw, but none of those helped.

Keep in mind that the node modules(yo generators are also node modules) that were previously installed in /usr/local might no longer be available and will require re-intalling.

Community
  • 1
  • 1
Oleg Belousov
  • 9,633
  • 12
  • 68
  • 119
  • Thanks very much for your suggestion. I tried what you suggest, and I've confirmed that my $NODE_PATH and my NPM root are equal. (I'm on Mac so the values are slightly different from the ones you give. `$NODE_PATH` and `npm config get prefix` are both `/Users/joanna/.node/lib/node_modules`). I've tried reinstalling Yeoman, and I still get `yo: command not found`. Any ideas? – Joanna Marsden Jan 20 '14 at 17:22
  • Followed this tip, no dice, still yo: command not found... :( – Tyguy7 Jun 30 '14 at 01:40
  • Worked for me. Thanks! – Gamak Oct 22 '14 at 16:46
13

For me on Ubuntu only the following worked for me...

Ubuntu

Tested on Ubuntu 14.04.2

This was a base install of Ubuntu 14.04.2 on VirtualBox using ubuntu-trusty-64.

I had just installed node and npm fresh and they were working well.

npm install -y -g yo
echo export PATH="$HOME/npm/bin:$PATH" >> ~/.bashrc
npm config set prefix ~/npm
echo "export NODE_PATH=$NODE_PATH:/home/$USER/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
npm install -y -g yo

yes I had to install yeoman, fix the path issues, then reinstall yeoman.

The explanations are above from Oleg Tikhonov and bfred.it

Community
  • 1
  • 1
svnm
  • 17,405
  • 18
  • 82
  • 100
10

The source of the problem is that you have NODE_PATH set while using NVM at the same time. When you use NVM you shouldn't have a NODE_PATH variable at all, since NVM installs global packages in its version specific root.

Delete all packages that are in your NODE_PATH, remove the environment variable, and install yo and the generators or any other global packages you need. You will see that it stops complaining and everything ends up in the nvm subdirectory matching the current version.

When you start using a different Node version in NVM, reinstall the global packages. This will keep everything organised neatly by version like its meant to be.

More info on this discussion here: https://github.com/creationix/nvm/pull/97

Thijs Koerselman
  • 16,219
  • 15
  • 62
  • 89
4

After trying the above suggestion, I noticed that yeoman was installed, as expected, in /Users/joanna/.node/bin/yo. I set up symbolic links to yo, grunt, and bower in /usr/local/bin with

ln -s /Users/joanna/.node/bin/yo /usr/local/bin/yo
ln -s /Users/joanna/.node/bin/grunt /usr/local/bin/grunt
ln -s /Users/joanna/.node/bin/bower /usr/local/bin/bower

Everything works now, but I'm concerned that the links might cause problems in the future. Is there a better solution?

Joanna Marsden
  • 503
  • 1
  • 4
  • 10
  • A quick note for anyone running Linux. You may need to change your paths to something like this: ln -s /home/joanna/.node/bin/yo /usr/local/bin/yo – 8bithero Apr 11 '14 at 21:07
4

Just to add on,I am using OS X 10.11.1, the code as mentioned by steve works for me too.

npm install -y -g yo
echo export PATH="$HOME/npm/bin:$PATH" >> ~/.bashrc
npm config set prefix ~/npm
echo "export NODE_PATH=$NODE_PATH:/home/$USER/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
npm install -y -g yo
Jason
  • 102
  • 1
  • 4
  • if there is any error when calling "npm install -y -g yo", follow the recommendations by running "sudo npm install -y -g yo". – Jason Feb 15 '16 at 16:34
1

In my case i had to execute :

npm config delete prefix

then set a nvm version

nvm use 8

and it works

Badr Bellaj
  • 6,763
  • 1
  • 29
  • 30
0

I used :

$HOME/npm/bin

And it pretty worked !

In MAC OSX

Despertaweb
  • 1,253
  • 15
  • 27
0

Check where your npm is installed:

where npm

Running above command will list the directory where npm is, as follows:

/usr/local/Cellar/node/5.1.0/libexec/npm/bin/npm

Copy the path till bin folder and export the same as a PATH variable, as below:

export PATH=$PATH:/usr/local/Cellar/node/5.1.0/libexec/npm/bin
Arpit Aggarwal
  • 21,748
  • 13
  • 80
  • 99