Changing Ruby version

Eric Wong normalperson at
Thu Feb 14 20:20:07 UTC 2013

Jérémy Lecour <jeremy.lecour at> wrote:
> Hi,
> I'm using Unicorn with rbenv to have different Ruby versions between projects.
> This morning, I wanted to change the Ruby version used by an app.
> I've updated the content of .ruby-version, then sent a USR2 signal to
> the master process to restart Unicorn (as I always do).
> I've noticed that it was still using the "old" Ruby binary.

I'm not familiar with rbenv, but you need to use the same "unicorn"
executable script for both installations (changing the shebang (#!)
line will do.

Otherwise, you can tweak Unicorn::HttpServer::START_CTX
(ref: )

> If I started a new irb console, the Ruby was correct.

This is probably because the shell you started irb from has the new
environment variables needed to find your new Ruby.  unicorn was
started from a different parent shell/process which had different
environment variables.

You may also need to modify ENV in a before_exec hook if there are
other environment variables your app depends on which a different
Ruby installation would change.

> Then I thought that maybe the way forking works allows to change the
> version of Unicorn itself and everything "below", but not the Ruby
> binary.
> Am I right ?
> Is there a way to do a rolling restart and change the Ruby binary at
> the same time?

What you're doing is switching between Ruby installations (to different
paths).  unicorn still supports this, but it's a little more involved
and involves modifying START_CTX (and possibly ENV).

The "upgrade" case is easiest when a new version of Ruby is installed
over the old one (this is the common case for OS package managers
(e.g.  RPM/dpkg/ports)).

More information about the mongrel-unicorn mailing list