Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "yo: command not found" after installing Yeoman

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

like image 565
Joanna Marsden Avatar asked Jan 18 '14 23:01

Joanna Marsden


People also ask

Where do I find NPM?

In a web browser, navigate to https://nodejs.org/en/download/. Click the Windows Installer button to download the latest default version. At the time this article was written, version 10.16.0-x64 was the latest version. The Node.js installer includes the NPM package manager.


2 Answers

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

like image 77
fregante Avatar answered Sep 18 '22 01:09

fregante


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.

like image 37
Oleg Belousov Avatar answered Sep 18 '22 01:09

Oleg Belousov