Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

-bash: cordova: command not found; or -bash: phonegap: command not found

I am not going to ask a question, but answer one, as I have found this advice nowhere online thus far and have just figured this out myself. It's good to share, right?


So on the command line, I did this:

sudo npm install -g cordova
sudo npm install -g phonegap

Which worked fine, but when I then ran either of these lines:

My-MacBook-Pro:~ username$ cordova
My-MacBook-Pro:~ username$ phonegap

I got these messages:

-bash: cordova: command not found
-bash: phonegap: command not found

Why? It turned out that the permissions on my /usr/local/lib directory were set to "everyone: No Access". I changed that to "everyone: Read only" and tried again.

My-MacBook-Pro:~ username$ cordova
My-MacBook-Pro:~ username$ phonegap

This time they worked! As a test I turned it back to "everyone: No Access" to see if it really was the problem. This time I got different messages:

-bash: /usr/local/bin/cordova: Permission denied
-bash: /usr/local/bin/phonegap: Permission denied

The outcome was the same though, I could not call either cordova or phonegap through the command line (I'm including these last two denial messages just in case anyone searches on them).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm on Mac Os Mountain Lion. After several attempts, turns out the solution is pretty quick.

Before installing Cordova, make sure you are the owner of the folders it's going to install into. Open terminal and type:

sudo chown -R $USER /usr/local/bin
sudo chmod -R 0775 /usr/local/bin

sudo chown -R $USER /usr/local/lib/node_modules
sudo chmod -R 0775 /usr/local/lib/node_modules
npm install -g cordova

If you installed a new version of node.js, you could still get some error. Try deleting npm cache:

sudo npm cache clear
npm install -g cordova

Then type cordova and good luck ;)

EDIT: now updated to work with macOs Mojave.

Note: Mojave won't allow you to change the ownership of /usr/local/altogether, throwing an error

chown: /usr/local: Operation not permitted

The fix is pretty easy, we just need to specify the path to the node_modules subfolder.

This change will also fix similar common issues when installing many other popular packages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...