unicorn/nginx rbdev seting ruby version

20 views
Skip to first unread message

Ben Edwards

unread,
Sep 12, 2017, 3:25:08 PM9/12/17
to Ruby on Rails: Talk
Hi, ive managed to get unicorn/nginx working (using https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04) 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.

Walter Lee Davis

unread,
Sep 12, 2017, 3:48:52 PM9/12/17
to rubyonra...@googlegroups.com
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

> On Sep 12, 2017, at 3:25 PM, Ben Edwards <lo...@funkytwig.com> wrote:
>
> Hi, ive managed to get unicorn/nginx working (using https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04) 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.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/15d10ba9-f588-43ee-8184-cc27aa39f3f1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ben Edwards

unread,
Sep 12, 2017, 4:18:50 PM9/12/17
to Ruby on Rails: Talk
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?

Walter Lee Davis

unread,
Sep 12, 2017, 5:13:27 PM9/12/17
to rubyonra...@googlegroups.com

> On Sep 12, 2017, at 4:18 PM, Ben Edwards <lo...@funkytwig.com> wrote:
>
> 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

>
> On Tuesday, September 12, 2017 at 8:48:52 PM UTC+1, Walter Lee Davis wrote:
> 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
>
> > On Sep 12, 2017, at 3:25 PM, Ben Edwards <lo...@funkytwig.com> wrote:
> >
> > Hi, ive managed to get unicorn/nginx working (using https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04) 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.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/15d10ba9-f588-43ee-8184-cc27aa39f3f1%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/dd3b868e-54bd-4389-ab58-974e8dfe8bcf%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages