New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sudo best practice #127

grosser opened this Issue Oct 18, 2011 · 7 comments


None yet
6 participants
Copy link

grosser commented Oct 18, 2011

whats the simples / best way to use the same commands with sudo ?

my current solution is

# /root/.bashrc
export PATH="$home/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

ln -s /home/micha/.rbenv/ /root/.rbenv


This comment has been minimized.

Copy link

grosser commented Oct 18, 2011

Improved version without any hacks:

function rbenvsudo(){
  shift 1
  sudo $(rbenv which $executable) $* 

could you add this to rbenv, sure lots of people what this especially if they used rvmsudo before...


This comment has been minimized.

Copy link

josh commented Oct 18, 2011

We made some changes to better support calling shims in sudo. See #66 and 964c12f.

However, rbenv itself isn't intended to be invoked in a sudo shell unless you specifically set that up in you root env.

@josh josh closed this Oct 18, 2011


This comment has been minimized.

Copy link

grosser commented Oct 18, 2011

so the intended way is to install it separately in /root ?


This comment has been minimized.

Copy link

fluxsaas commented Feb 14, 2012

i also would like to know what the best approach is. i have to setup foreman for my production server (capistrano task):

  sudo bundle exec foreman export upstart /etc/init -a #{application} -u #{user} -l #{release_path}/log/foreman"

obviously it's not working, because of the "sudo". it's better to install rbenv for sudo ? or did i miss sth. ?

i could do:

 sudo $(rbenv which foreman) export upstart /etc/init -a #{application} -u #{user} -l #{release_path}/log/foreman"

it finds foreman, but breaks with an error: "/usr/bin/env: ruby: No such file or directory"

 sudo env

the rbenv ruby is not set in my sudo path. after reading the ticket: #66 (comment) it should be added ?

i did not followed the guide on but i installed it for my deploy user. so it "should" be fine.


a workaround is to use:

  sudo env PATH=$PATH bundle exec foreman export upstart /etc/init -a #{application} -u #{user} -l #{release_path}/log/foreman"

which preserves the PATH variables of the "normal" user so it finds the rbenv gems and ruby.

but still wrong isn't it ?


This comment has been minimized.

Copy link

mrrooijen commented Apr 3, 2012

@fluxsaas I just add this function to my env (for example .bashrc) then just run rbenvsudo foreman export upstart /etc/init works perfectly fine for me as a non-root UNIX user, it'll write the conf files to /etc/init without running into permission errors.


This comment has been minimized.

Copy link

henry74 commented Nov 10, 2014

Can someone explain how I would incorporate this script into the mina workflow? Do I add a separate run command into the deploy.rb file? Do I run it manually? Sorry it's hard to follow all the different comments/solutions/suggestions.


This comment has been minimized.

Copy link

mislav commented Nov 14, 2014

@henry74 Maybe somebody who solved this can help you, but we generally don't provide support for various usage of rbenv in combination with 3rd party software.

rbenv will always work when rbenv executable and "$(rbenv root)"/shims directory are on the top of the PATH. It's that simple, really. However, deployment environments and sudo often clear out the PATH (this is by design) and set up their own without respecting ~/.bash_profile or similar shell initialization files. In such cases, the person who is setting up the deployment environment has to ensure that rbenv in PATH will be preserved. It all boils down to having correct PATH, so always start debugging from there.

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