【问题标题】:Permission denied editing .bash_profile rbenv init on mac权限被拒绝在 mac 上编辑 .bash_profile rbenv init
【发布时间】:2018-08-14 10:41:57
【问题描述】:

在 mac 上运行 rbenv init 时挂断了编辑 .bash_profile。

$ rbenv init
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

但得到消息: -bash: /Users/macbookpro/.bash_profile: 权限被拒绝

我尝试直接编辑 .bash_profile 但收到消息:

我找到了这个命令来查看用户:

$ ls -la ~ | grep bash

它显示:

-rw------- 1 macbookpro .bash_history
-rw-r--r-- 1 root       .bash_profile

如果我使用命令打开文件:

$ sudo nano ~/.bash_profile

我想我需要将它添加到 .bash_profile:

$ export PATH="$HOME/.rbenv/bin:$PATH"

或者它只是它的内部“部分”? 另外,我该如何保存或者我们有更简单的解决方案(假装我的名字是 Fname-Lname)?

【问题讨论】:

  • 我可以把它带回我的所有权或共享吗?

标签: bash macos terminal rbenv


【解决方案1】:

您需要使用sudo 才能在macOS 上编辑/附加~/.bash_profile

sudo echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

或者就像你在问题结束时所做的那样。

【讨论】:

  • 我在使用 sudo 时仍然收到相同的消息:-bash: /Users/macbookpro/.bash_profile: Permission denied
  • 您可以尝试将所有权更改为您的用户:chown $(id -u -n) ~/.bash_profile,或者如果这不起作用,请尝试:sudo chown $(id -u -n) ~/.bash_profile
  • 您最后的评论很有帮助。谢谢。
【解决方案2】:

我遇到了同样的问题,我给了 .bash_profile 可写权限。

cd ~
sudo chmod 0777 .bash_profile
nano .bash_profile

添加修改后,您现在可以使用^O 保存文件并输入(返回),然后使用^x 退出。

注意: ^ 是控制按钮

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-19
    • 2012-04-14
    • 2016-04-10
    • 2015-11-08
    • 1970-01-01
    • 2015-01-28
    • 2015-10-13
    • 1970-01-01
    相关资源
    最近更新 更多