The sudo, by the looks of what I have seen in some forums, is why I am getting an error when running sudo ionic emulate ios
in this post New to ionic - can’t build for ios (9) on El Capitan, and sudo ionic is required, deprecated npmconf. (I am running El Capitan btw).
sudo,通过我在一些论坛上看到的外观,为什么我在这篇文章中运行sudo离子模拟ios时出现错误新的离子 - 无法在El Capitan和sudo上为ios(9)构建需要离子,不推荐使用npmconf。 (我正在运行El Capitan btw)。
Whenever I need to use an ionic, npm, or cordova command, I always have to put sudo
in front of it otherwise I get a "bash command not found" error. I have tried to use this fix https://www.npmjs.com/package/npm-sudo-fix but it doesn't work. This is what happens in the log:
每当我需要使用离子,npm或cordova命令时,我总是要把sudo放在它前面,否则我会收到“bash command not found”错误。我试图使用此修复程序https://www.npmjs.com/package/npm-sudo-fix但它不起作用。这是日志中发生的事情:
Dylans-MBP:Ionic Projects Dylan $ sudo npm install -g npm-sudo-fix
Password:
/usr/local/bin/npm-sudo-fix -> /usr/local/lib/node_modules/npm-sudo-fix/index.js
npm-sudo-fix@0.1.3 /usr/local/lib/node_modules/npm-sudo-fix
└── spawny@0.0.1 (cmdify@0.0.4)
Dylans-MBP:Ionic Projects Dylan$ sudo npm-sudo-fix
chown: /users/root/.npm: No such file or directory
1 个解决方案
#1
11
Edit (28 August 2018):
编辑(2018年8月28日):
I wrote this post and answer many years ago when I was not very familiar with the terminal. Now that I am more experienced, I can recommend the better solution. It is good practice to avoid unnecessary usages of sudo.
多年前我写这篇文章并回答我对终端不太熟悉的问题。既然我更有经验,我可以推荐更好的解决方案。避免不必要的sudo使用是一种好习惯。
I believe the problem is caused by installing node JS from the installer from the node JS website. This version of node JS seems to write various files in the filesystem as root, potentially (and unnecessarily) causing global packages to require root permissions to be installed.
我认为问题是由安装程序从节点JS网站安装节点JS引起的。这个版本的节点JS似乎以root身份在文件系统中编写各种文件,可能(并且不必要地)导致全局包需要安装root权限。
The ideal solution would be to completely remove node JS, that was installed from the node JS installer from the website, from your machine (see https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/). Then install node from a commandline package manager, such as homebrew.
理想的解决方案是从您的机器上完全删除从网站上的节点JS安装程序安装的节点JS(请参阅https://stackabuse.com/how-to-uninstall-node-js-from-mac- OSX /)。然后从命令行包管理器安装节点,例如homebrew。
Original Answer (2016)
原答案(2016)
Finally came up with a solution by playing with the permissions! Hopefully I didn't stuff up anything. (I am a terminal noob btw.) Anyway, here's the solution.
终于通过玩权限想出了解决方案!希望我没有填充任何东西。 (我是终端菜鸟顺便说一句。)无论如何,这是解决方案。
Run this code here in the terminal (you may or may not have to run cd ..
before hand)
在终端中运行此代码(您可能需要也可能不需要先运行cd ..)
sudo chown -R $USER /usr/local/
This changes the permissions of every thing inside the local folder (hence the -R
which means recursive). (I found this line somewhere in the ionic forums).
这会更改本地文件夹中每个内容的权限(因此-R表示递归)。 (我在离子论坛的某个地方发现了这条线)。
Now, you have to reinstall cordova and ionic
现在,你必须重新安装cordova和离子
sudo npm install -g cordova
sudo npm install -g ionic
For me anyway, after I do this, I can type ionic
and not get any errors. I get this in the terminal if I run cordova
though.
无论如何,在我这样做之后,我可以输入离子而不会出现任何错误。如果我运行cordova,我会在终端得到这个。
/usr/local/lib/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:53
throw err;
^
Error: EACCES: permission denied, open '/Users/Dylan/.config/configstore/update-notifier-cordova.json'
You don't have access to this file.
What I did to fix this was do this (after opening up a new terminal window):
我做的是解决这个问题(打开一个新的终端窗口后):
sudo chown -R $USER Dylan
(Dylan is my user folder; replace it with yours. Also, you may have to do a cd ..
before running that line And that fixes the permissions for that config file. Now running cordova
works without errors! Woot! That error might come back though, so you have to run that line of code again.
(Dylan是我的用户文件夹;用你的用户文件夹替换它。另外,你可能必须在运行该行之前做一个CD ..并且修复了该配置文件的权限。现在运行cordova没有错误!Woot!那个错误可能会来回过头来,所以你必须再次运行那行代码。
Hope this helps somebody!
希望这有助于某人!
#1
11
Edit (28 August 2018):
编辑(2018年8月28日):
I wrote this post and answer many years ago when I was not very familiar with the terminal. Now that I am more experienced, I can recommend the better solution. It is good practice to avoid unnecessary usages of sudo.
多年前我写这篇文章并回答我对终端不太熟悉的问题。既然我更有经验,我可以推荐更好的解决方案。避免不必要的sudo使用是一种好习惯。
I believe the problem is caused by installing node JS from the installer from the node JS website. This version of node JS seems to write various files in the filesystem as root, potentially (and unnecessarily) causing global packages to require root permissions to be installed.
我认为问题是由安装程序从节点JS网站安装节点JS引起的。这个版本的节点JS似乎以root身份在文件系统中编写各种文件,可能(并且不必要地)导致全局包需要安装root权限。
The ideal solution would be to completely remove node JS, that was installed from the node JS installer from the website, from your machine (see https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/). Then install node from a commandline package manager, such as homebrew.
理想的解决方案是从您的机器上完全删除从网站上的节点JS安装程序安装的节点JS(请参阅https://stackabuse.com/how-to-uninstall-node-js-from-mac- OSX /)。然后从命令行包管理器安装节点,例如homebrew。
Original Answer (2016)
原答案(2016)
Finally came up with a solution by playing with the permissions! Hopefully I didn't stuff up anything. (I am a terminal noob btw.) Anyway, here's the solution.
终于通过玩权限想出了解决方案!希望我没有填充任何东西。 (我是终端菜鸟顺便说一句。)无论如何,这是解决方案。
Run this code here in the terminal (you may or may not have to run cd ..
before hand)
在终端中运行此代码(您可能需要也可能不需要先运行cd ..)
sudo chown -R $USER /usr/local/
This changes the permissions of every thing inside the local folder (hence the -R
which means recursive). (I found this line somewhere in the ionic forums).
这会更改本地文件夹中每个内容的权限(因此-R表示递归)。 (我在离子论坛的某个地方发现了这条线)。
Now, you have to reinstall cordova and ionic
现在,你必须重新安装cordova和离子
sudo npm install -g cordova
sudo npm install -g ionic
For me anyway, after I do this, I can type ionic
and not get any errors. I get this in the terminal if I run cordova
though.
无论如何,在我这样做之后,我可以输入离子而不会出现任何错误。如果我运行cordova,我会在终端得到这个。
/usr/local/lib/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:53
throw err;
^
Error: EACCES: permission denied, open '/Users/Dylan/.config/configstore/update-notifier-cordova.json'
You don't have access to this file.
What I did to fix this was do this (after opening up a new terminal window):
我做的是解决这个问题(打开一个新的终端窗口后):
sudo chown -R $USER Dylan
(Dylan is my user folder; replace it with yours. Also, you may have to do a cd ..
before running that line And that fixes the permissions for that config file. Now running cordova
works without errors! Woot! That error might come back though, so you have to run that line of code again.
(Dylan是我的用户文件夹;用你的用户文件夹替换它。另外,你可能必须在运行该行之前做一个CD ..并且修复了该配置文件的权限。现在运行cordova没有错误!Woot!那个错误可能会来回过头来,所以你必须再次运行那行代码。
Hope this helps somebody!
希望这有助于某人!