[英]sudo open -e ~/.bash_profile Permission denied mac
I am trying to edit bash_profile file to add path to my sdk through the following command on my mac machine.我正在尝试编辑 bash_profile 文件以通过我的 mac 机器上的以下命令添加到我的 sdk 的路径。 sudo touch ~/.bash_profile;
须藤触摸 ~/.bash_profile; open -e ~/.bash_profile
打开 -e ~/.bash_profile
It opens the file in TextEdit but does not allow me to edit it.它在 TextEdit 中打开文件,但不允许我编辑它。 Though i have given super-user permission and password while running the above command.
尽管我在运行上述命令时已授予超级用户权限和密码。 It is giving me following message when i try to edit it.
当我尝试编辑它时,它给了我以下消息。
"You don't own the file “.bash_profile” and don't have permission to write to it. You can duplicate this document and edit the duplicate. Only the duplicate will include your changes." “您不拥有“.bash_profile”文件,也没有写入权限。您可以复制此文档并编辑副本。只有副本才会包含您的更改。” I am new to mac.
我是 mac 新手。 So please elaborate your answers.
所以请详细说明你的答案。
The problem is that the file isn't owned by your user, but by root
.问题是该文件不属于您的用户,而是属于
root
。 You need to change the owner of the file to your user, then you can open and edit the file without the use of sudo
:您需要将文件的所有者更改为您的用户,然后您可以在不使用
sudo
情况下打开和编辑文件:
sudo chown farheen ~/.bash_profile
This will, as the super-user, change the owner of the file back to you.作为超级用户,这会将文件的所有者更改回您。
For Mac User Catalina,对于 Mac 用户 Catalina,
.bash_profile
not open, they need grant permission to edit this file. .bash_profile
未打开,他们需要授予权限才能编辑此文件。 You can achieve by below steps您可以通过以下步骤实现
1) Open the terminal and enter below command ex: sudo chown iMac ~/.bash_profile
1)打开终端并输入以下命令例如:
sudo chown iMac ~/.bash_profile
sudo chown {your username} ~/.bash_profile
2) Open editor in the terminal, here i used nano
2)在终端打开编辑器,这里我用的是
nano
nano .bash_profile
3) Edit your text you want. 3)编辑你想要的文字。
4) To save the changes you've made, press Ctrl + O
4) 要保存您所做的更改,请按
Ctrl + O
5) To exit nano, press Ctrl + X
5) 要退出 nano,请按
Ctrl + X
6) And finally to load your changes, enter below command 6)最后加载您的更改,输入以下命令
source .bash_profile
OR或者
You can give permission and make it executable file using like below:您可以使用如下方式授予权限并使其成为可执行文件:
That error likely means that ' bash_profile ' isn't executable.该错误可能意味着“ bash_profile ”不可执行。 If it's in the current directory, you can make it executable with chmod +x bash_profile .
如果它在当前目录中,您可以使用chmod +x bash_profile使其可执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.