Skip to content

Instantly share code, notes, and snippets.

@vyder
Created October 17, 2016 09:24
Show Gist options
  • Save vyder/2386a03affba03dadb2bc7c3f0bf7b8a to your computer and use it in GitHub Desktop.
Save vyder/2386a03affba03dadb2bc7c3f0bf7b8a to your computer and use it in GitHub Desktop.
Using rbenv in an XCode 'Run Script Phase'

If anybody stumbles across this from Google, I found that the simplest thing to do was:

Have devs install rbenv on their machines, and add ~/.rbenv/shims to the PATH in the XCode build script like:

export PATH=~/.rbenv/shims:$PATH
# Exec rest of your script
# ...

A slightly more complicated, but more customizable solution is to have your script start with the following:

XCODE_ENV=.xcode-env
XCODE_LOCAL_ENV=.xcode-env-local

# Setup your env variable overrides here
if [ -f $XCODE_LOCAL_ENV ]; then
    source $XCODE_LOCAL_ENV
fi

# Source default environment variables
source $XCODE_ENV

# Exec rest of your script
# ...

The .xcode-env file contains:

#
# Default XCode ENV
#

# Set RBENV_SHIMS if undefined
if [ -z $RBENV_SHIMS ]; then
    RBENV_SHIMS=~/.rbenv/shims
fi
export PATH=$RBENV_SHIMS:$PATH

So, if you want to specify alternative environment variables, you can create a .xcode-env-local (which is gitignored) with content like:

RBENV_SHIMS=/some/other/path/to/.rbenv/shims
@acevif
Copy link

acevif commented Dec 27, 2020

@vyder
Copy link
Author

vyder commented Dec 27, 2020

You're welcome ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment