Installing Yeoman - “Yo command not found”

2019-06-06 18:50发布

I have installed node.js and set up npm on my Yosemite install using the npm-g_nosudo script. When I then run npm install -g yo I see a bunch of content scroll through my terminal window, with no errors, and it completes. I then type yo and OS X tells me that it can't find the command.

Sullys-MacBook-Pro:~ Sully$ npm install -g yo
/Users/Sully/npm/bin/yo -> /Users/Sully/npm/lib/node_modules/yo/lib/cli.js

> yo@1.4.6 postinstall /Users/Sully/npm/lib/node_modules/yo
> yodoctor


Yeoman Doctor
Running sanity checks on your system

✔ Global configuration file is valid
✔ NODE_PATH matches the npm root
✔ No .bowerrc file in home directory
✔ No .yo-rc.json file in home directory

Everything looks all right!
yo@1.4.6 /Users/Sully/npm/lib/node_modules/yo
├── titleize@1.0.0
├── array-uniq@1.0.2
├── figures@1.3.5
├── user-home@1.1.1
├── opn@1.0.2
├── humanize-string@1.0.1 (decamelize@1.0.0)
├── sort-on@1.2.0 (dot-prop@2.0.0)
├── async@0.9.0
├── yeoman-character@1.0.1 (supports-color@1.3.1)
├── string-length@1.0.0 (strip-ansi@2.0.1)
├── cross-spawn@0.2.9 (lru-cache@2.6.2)
├── findup@0.1.5 (commander@2.1.0, colors@0.6.2)
├── chalk@1.0.0 (escape-string-regexp@1.0.3, ansi-styles@2.0.1, supports-color@1.3.1, strip-ansi@2.0.1, has-ansi@1.0.3)
├── yosay@1.0.3 (ansi-regex@1.1.1, ansi-styles@2.0.1, strip-ansi@2.0.1, word-wrap@1.0.3, pad-component@0.0.1, taketalk@1.0.0, minimist@1.1.1)
├── root-check@1.0.0 (downgrade-root@1.1.0, sudo-block@1.2.0)
├── meow@3.1.0 (object-assign@2.0.0, camelcase-keys@1.0.0, minimist@1.1.1, indent-string@1.2.1)
├── package-json@1.1.0 (registry-url@3.0.3)
├── npm-keyword@1.1.1 (registry-url@3.0.3)
├── update-notifier@0.3.2 (is-npm@1.0.0, latest-version@1.0.0, semver-diff@2.0.0)
├── got@2.9.2 (lowercase-keys@1.0.0, timed-out@2.0.0, object-assign@2.0.0, is-stream@1.0.1, prepend-http@1.0.1, nested-error-stacks@1.0.0, statuses@1.2.1, infinity-agent@2.0.3, duplexify@3.3.0, read-all-stream@2.1.2)
├── fullname@1.1.0 (npmconf@2.1.1)
├── yeoman-environment@1.2.5 (log-symbols@1.0.2, escape-string-regexp@1.0.3, untildify@2.0.0, diff@1.4.0, text-table@0.2.0, debug@2.1.3, mem-fs@1.1.0, globby@1.2.0, grouped-queue@0.3.0)
├── configstore@0.3.2 (object-assign@2.0.0, xdg-basedir@1.0.1, osenv@0.1.0, graceful-fs@3.0.6, uuid@2.0.1, mkdirp@0.5.0, js-yaml@3.3.0)
├── insight@0.5.3 (object-assign@2.0.0, lodash.debounce@3.0.3, os-name@1.0.3, tough-cookie@0.12.1, request@2.55.0)
├── lodash@3.8.0
├── yeoman-doctor@1.3.2 (object-values@1.0.0, log-symbols@1.0.2, each-async@1.1.1, twig@0.7.2)
└── inquirer@0.8.3 (ansi-regex@1.1.1, cli-width@1.0.1, through@2.3.7, readline2@0.1.1, rx@2.5.2)
Sullys-MacBook-Pro:~ Sully$ yo
-bash: yo: command not found

I also tried using source .bash_profile and rebooting. The command is still not found. Am I doing something wrong?

This is my .bash_profile

# Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x
export COCOS_CONSOLE_ROOT=/Users/Sully/Development/Libraries/cocos2d-x-3.5/tools/cocos2d-console/bin
export PATH=$COCOS_CONSOLE_ROOT:$PATH

# Add environment variable COCOS_TEMPLATES_ROOT for cocos2d-x
export COCOS_TEMPLATES_ROOT=/Users/Sully/Development/Libraries/cocos2d-x-3.5/templates
export PATH=$COCOS_TEMPLATES_ROOT:$PATH

# NPM
export BIN_ROOT=/usr/local/bin
export PATH=$BIN_ROOT:$PATH

This is my full $PATH

Sullys-MacBook-Pro:~ Sully$ echo $PATH
/usr/local/share/npm/bin:/usr/local/bin:/Users/Sully/Development/Libraries/cocos2d-x-3.5/templates:/Users/Sully/Development/Libraries/cocos2d-x-3.5/tools/cocos2d-console/bin:/Users/Sully/.dnx/runtimes/dnx-mono.1.0.0-beta4/bin:/usr/local/bin:/Users/Sully/Development/Libraries/cocos2d-x-3.5/templates:/Users/Sully/Development/Libraries/cocos2d-x-3.5/tools/cocos2d-console/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

2条回答
神经病院院长
2楼-- · 2019-06-06 18:53

This was resolved by adding export PATH=/Users/UserAccountName/npm/bin:$PATH to my ~/.bash_profile and restarting Terminal.app.

查看更多
你好瞎i
3楼-- · 2019-06-06 19:11

I have faced the same problem after installing everything succesfully, I resolved it using the following method creating symbolic links to yo, grunt, bower like the following :

For Yo

praveen@praveen-lenovo:~$ sudo ln -s /home/praveen/.npm-global/bin/yo /usr/bin/yo

For Grunt

praveen@praveen-lenovo:~$ sudo ln -s /home/praveen/.npm-global/bin/grunt /usr/bin/grunt

For Bower

praveen@praveen-lenovo:~$ sudo ln -s /home/praveen/.npm-global/bin/bower /usr/bin/bower

Here in the above commands the common path /home/praveen/.npm-global/bin/ may change according to your system folder structure.

查看更多
登录 后发表回答