当前位置 : 主页 > 编程语言 > ruby >

ruby – 如何在Mac OS X上安装没有sudo的gem

来源:互联网 收集:自由互联 发布时间:2021-06-23
我读了很多帖子,但到目前为止还没有人做过这个伎俩. 我怎么能在OSX(El Capitan Beta)上为我自己的用户安装一个gem?帖子建议例如指定-user-install但我不能在没有sudo的情况下调用gem,因为它
我读了很多帖子,但到目前为止还没有人做过这个伎俩.

我怎么能在OSX(El Capitan Beta)上为我自己的用户安装一个gem?帖子建议例如指定-user-install但我不能在没有sudo的情况下调用gem,因为它会抛出权限错误.

我跟着“Install gem as user on OSX 10.10 Yosemite”但仍然不能打电话给宝石.

我按照上面的指南安装了Homebrew,安装了rbenv,安装了一个带rbenv的Ruby版本,检查它是否正确加载,但指南的最后一步是调用gem install,我仍然无法做到.

安装rbenv后调用gem会导致:

/Users/Me/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/stub_specification.rb:71:in `initialize': 
Permission denied @ rb_sysopen - /Users/Ne/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/speci

rbenv env转储:

RBENV_VERSION=2.1.5
RBENV_ROOT=/Users/Me/.rbenv
RBENV_HOOK_PATH=:/Users/Me/.rbenv/rbenv.d:
  /usr/local/etc/rbenv.d:
  /etc/rbenv.d:
  /usr/lib/rbenv/hooks
PATH=/Users/Me/.rbenv/versions/2.1.5/bin:
  /usr/local/Cellar/rbenv/0.4.0/libexec:
  /Users/Me/.rbenv/plugins/rbenv-env/bin:
  /Users/Me/.rbenv/shims:
  /usr/local/heroku/bin:
  /usr/local/sbin:
  /usr/local/bin:
  /usr/local/share/npm/bin:
  /Applications/Atom.app/Contents/Resources/app/apm/bin:
  /Users/Me/.bin:
  /Applications/Atom.app/Contents/Resources/app/apm/node_modules/atom-package-manager/bin:
  /usr/local/bin:/usr/bin:
  /bin:
  /usr/sbin:/sbin:
  /opt/X11/bin:
  /usr/local/MacGPG2/bin
RBENV_DIR=/Users/Me/.rbenv/plugins

“brew and gem both throws ‘Permission denied’ error whenever I run it”似乎有关,虽然除了使用我可能要做的其他方法之外没有解决.

如果你不能使用没有sudo的gem,听起来你没有正确初始化rbenv因为垫片不可用.

这些步骤来自the documentation.确认您已完成所有操作:

Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.

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

Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.

Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

Add rbenv init to your shell to enable shims and autocompletion.

$echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Same as in previous step, use ~/.bashrc on Ubuntu, or ~/.zshrc for Zsh.

Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:

$type rbenv
#=> "rbenv is a function"
网友评论