使用rvm在Xcode Run Script构建阶段强制使用特定的Ruby

在Xcode之外我使用特定版本的Ruby,使用RVM来管理多个Ruby安装。

Apple的命令行开发工具在/usr/bin/ruby安装Ruby,版本为1.8.7。

我通过RVM使用1.9.3。

有没有办法在运行Run Script构建阶段时强制Xcode使用我的1.9.3安装?

我已经尝试将Shell路径设置为我特定Ruby的完整路径,但这似乎没有什么区别,我的意思是我在1.9.3中安装的特定Gems不可用/可见在Xcode中运行时的脚本。

如果我在命令行上通过xcodebuild运行我的项目,则Run Script阶段使用我的特定Ruby,因为它是在我的shell环境中运行的(即使项目文件中的Shell路径设置为/usr/bin/ruby ,它也是如此)仍然使用我的1.9.3)。

我该怎么做才能使IDE使用我的1.9.3 Ruby安装?

在Xcode的脚本开头尝试这个:

 source "$HOME/.rvm/scripts/rvm" 

我有同样的(好的,更糟的)问题,随后的代码对我有用。 要实现的关键是,在命令行中,您正在使用/bin/rvm ,但在shell脚本中,为了让rvm更改环境,您必须使用一个函数 ,并且必须首先加载通过调用source /scripts/rvm将该函数发送到shell脚本。 更多关于这一切。

此代码也是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 (eg .ruby-version) for the # pwd using this function call. rvm use . 

作为一个protip,我发现在shell.pbxproj文件中嵌入shell代码令人讨厌。 对于除了最微不足道的东西之外的所有东西,我的实际运行脚本步骤通常只是对外部脚本的单行调用:

在此处输入图像描述