-bash:cordova:找不到命令;或 -bash: phonegap: 命令未找到 [英] -bash: cordova: command not found; or -bash: phonegap: command not found

查看:58
本文介绍了-bash:cordova:找不到命令;或 -bash: phonegap: 命令未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不打算问一个问题,而是回答一个问题,因为到目前为止我在网上找不到这个建议,而且我自己才弄明白这一点.很好分享,对吧?

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

我收到了这些消息:

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

为什么?原来我的/usr/local/lib 目录的权限被设置为everyone: No Access".我将其更改为所有人:只读"并再次尝试.

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

结果是一样的,我无法通过命令行调用cordova或phonegap(我包括最后两条拒绝消息,以防有人搜索它们).

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).

推荐答案

我在 Mac Os Mountain Lion 上.经过多次尝试,结果证明解决方案非常快.

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

在安装 Cordova 之前,请确保您是它要安装到的文件夹的所有者.打开终端并输入:

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

如果您安装了新版本的 node.js,您仍然可能会遇到一些错误.尝试删除 npm 缓存:

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

然后输入 cordova 并祝你好运;)

Then type cordova and good luck ;)

现在更新为与 macOs Mojave 一起使用.

now updated to work with macOs Mojave.

注意:Mojave 不允许您更改 /usr/local/ 的所有权,从而引发错误

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

chown:/usr/local: 不允许操作

修复非常简单,我们只需要指定node_modules 子文件夹的路径.

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.

这篇关于-bash:cordova:找不到命令;或 -bash: phonegap: 命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆