unicorn/nginx rbdev seting ruby version

Hi, ive managed to get unicorn/nginx working (using How To Deploy a Rails App with Unicorn and Nginx on Ubuntu 14.04 | DigitalOcean) and i am using rbenv. The setup used a .rbenv-vars configuration file in the ruby app directory. what I cant figure out is how to specify what version of ruby to tell it to use. Ime ding this on my dev box, where I only have one version but when I put it on prod they have several so I need to specify which to use.

If you are in the directory containing the application, you can use the rbenv local command to get and set the ruby version to use within the app.

rbenv local 3.2.1

will set the ruby version. It does this by creating or modifying a .ruby-version file in the application root.

Walter

Thanks. OK, so if I do rbenv local in my app directory will unicorn use that version to run unicorn when I do ’ service unicorn_eventpuddle start '?

I was using ’ ruby server’ from bash on my dev box and had the following in my .bashrc so I used rbenv.

export RBENV_ROOT=/usr/local/rbenv export PATH=“$RBENV_ROOT/bin:$PATH” eval “$(rbenv init -)”

So do I need to put this in the

/etc/init.d/unicorn_``appname script as it is run as root (I think).

Also wondering exactly how .ruby-version works. I know ‘rbenv local 3.2.1’ creates it but when I do ruby stuff does it just look in the current directory for the file or does it traverse up the directory tree until it fins one?

Thanks. OK, so if I do rbenv local in my app directory will unicorn use that version to run unicorn when I do 'service unicorn_eventpuddle start '?

I was using ' ruby server' from bash on my dev box and had the following in my .bashrc so I used rbenv.

export RBENV_ROOT=/usr/local/rbenv export PATH="$RBENV_ROOT/bin:$PATH" eval "$(rbenv init -)"

So do I need to put this in the /etc/init.d/unicorn_appname script as it is run as root (I think).

Also wondering exactly how .ruby-version works. I know 'rbenv local 3.2.1' creates it but when I do ruby stuff does it just look in the current directory for the file or does it traverse up the directory tree until it fins one?

Yes, I believe it works that way. If you have one at the global root, then it would be your last resort. Any ruby executable that does not specifically mark a particular ruby version using a "shebang" will run the local environment's idea of what constitutes ruby. Part of that comes from your path, but rbenv also hijacks that by creating shims to particular versions and rotating them in based on the lookup of the local version variable. I use rbenv at work, but I have much more experience with rvm, and still prefer it. That's a much larger hammer, as it hooks all shell commands to use your preferred ruby, and doesn't just shim the ruby command itself.

Walter