在 Xcode 之外,我使用特定版本的 Ruby,使用 RVM 管理多个 Ruby 安装。
Apple 的命令行开发工具将 Ruby 安装在 /usr/bin/ruby
并且版本为 1.8.7。
我通过 RVM 使用 1.9.3。
有没有办法强制 Xcode 在运行其运行脚本构建阶段时使用我的 1.9.3 安装?
我已经尝试将 Shell 路径设置为我的特定 Ruby 的完整路径,但这似乎没有什么不同,我的意思是我在 1.9.3 中安装的特定 Gems 不可用/在 Xcode 中运行时对脚本可见。
如果我在命令行上通过 xcodebuild
运行我的项目,运行脚本阶段会使用我的特定 Ruby,因为它是从我的 shell 环境中运行的(即使项目文件中的 Shell 路径是设置为 /usr/bin/ruby
,它仍然使用我的 1.9.3)。
如何让 IDE 使用我安装的 1.9.3 Ruby?
最佳答案
我遇到了同样(好吧,更糟)的问题,下面的代码对我有用。
要意识到的关键是,在命令行上,您正在使用 <something>/bin/rvm
,但是在 shell 脚本中,为了让 rvm 改变那个环境,你必须使用一个函数,而且你必须首先加载那个函数通过调用 source <something>/scripts/rvm
到您的 shell 脚本.关于这一切的更多信息 here .
这段代码也是gisted .
#!/usr/bin/env bash
# Xcode scripting does not invoke rvm. To get the correct ruby,
# we must invoke rvm manually. This requires loading the rvm
# *shell function*, which can manipulate the active shell-script
# environment.
# cf. http://rvm.io/workflow/scripting
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit 128
fi
# rvm will use the controlling versioning (e.g. .ruby-version) for the
# pwd using this function call.
rvm use .
作为提示,我发现在 project.pbxproj
中嵌入了 shell 代码令人讨厌的文件。除了最琐碎的事情之外,我的实际运行脚本步骤通常只是对外部脚本的一行调用:
关于ruby - 在 Xcode 运行脚本构建阶段使用 rvm 强制指定 Ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15474902/