ruby - 如何使用 Mac 的 Ruby 解释器(1.8)将 Vagrant 安装为 $HOME gem?

标签 ruby macos rubygems vagrant home-directory

我已经问过 installing python packages at $HOME .它运行完美。

现在,我打算安装 Vagrant .这是一个gem (一个 ruby​​ 包),我也想将它安装在我的 $HOME 文件夹中,但我不习惯,所以我在这里寻求帮助。

我已经跑了,

sudo gem update --system

接着是他们的mac tutorial .当我尝试使用他们的推荐安装 Vagrant 时:

gem install vagrant

我得到:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/bin directory.

(奇怪的是,只是 gem install vagrant 不起作用,我按照 Vagrant 官方网站上的指南在 vanilla 安装的 Mac 上进行操作,这里从未使用过 Ruby,但我得到了错误。特别是在使用时须藤 is not required .)

好的。使用 sudo 将解决它,但我不想在整个系统范围内安装此 gem,我想像使用 pip 一样将它们安装在 $HOME 中 - 我不知道如何在不搞乱这个的情况下做到这一点苹果机。有人可以帮助我如何以最好的方式做到这一点吗?如果我必须将 ~/.gem 添加到我的 $PATH 或类似的东西,我必须导出哪些变量。 (当我使用 sudo gem update --system 时,我是否已经把一切都搞砸了?)

有些人建议使用 rvm ,但我认为这是矫枉过正,因为我不打算针对系统 Ruby 开发 Ruby 应用程序,我只想运行 Vagrant。当然,如果没有别的办法,我就用它。

我的 gem 环境命令输出:

gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.10
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-10
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/user/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

编辑:我找到了一个 tutorial ,这表示我只需要添加到我的 .profile 中:

export GEM_HOME=$HOME/.gems
export PATH=$GEM_HOME/bin:$PATH

使用这种方法安全吗?

最佳答案

使用 tutorial approach I posted它似乎工作。如果这种方法在我的场景中有任何警告(我只想运行 ruby​​ 应用程序,不想开发它们)并且他们将接受我自己的答案,我将等待更有经验的 ruby​​ 开发人员。 :)

转录教程:

Recommended: Installing Gems to Your Home Directory

Where possible, avoid installing gems into the global system. This ensures that the gems that you install are easy to identify and manage, and do not interfere with the global Ruby installation.

As of RubyGems 1.3, RubyGems will automatically install gems into the directory specified by the GEM_HOME environment variable if the system location is not accessible. You will see that directories are created within your GEM_HOME directory to store gem files. This means that RubyGems will do the right thing when managing packages, provided that you do not run the gem utility with administrative privileges.

To do this, edit the .profile file in your home directory, and add or amend it to include these lines:

export GEM_HOME=$HOME/gems

export PATH=$GEM_HOME/bin:$PATH

This takes effect the next time that you login or create a terminal window.

The presence of the bin subdirectory on your PATH enables you to use any command-line utilities that are installed with your gem packages.

关于ruby - 如何使用 Mac 的 Ruby 解释器(1.8)将 Vagrant 安装为 $HOME gem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7297569/

相关文章:

ruby-on-rails - Rails 3.1 限制用户创建的对象

macos - 主 NSWindow 阴影不会像子窗口那样改变

macos - 适用于 Mac 应用程序的 Instagram API

ios - 如何阻止 Xcode 在 iphoneos 构建目录中查找 OS X 产品?

ruby - 在 Ubuntu 12.04 上编译 Postgres pg gem 时出错

jquery - Rails4 自动完成功能不起作用

ruby - Rspec:DRY 正面和负面案例的共享示例

ruby-on-rails - 没有路由匹配 [GET] "demo/hello"

ruby-on-rails - rpect 中的 Rails Activesupport 错误

ruby - 在 CLI gem 中,我在哪里存储第三方二进制可执行文件?