1

I have a system wide installation of RVM on a server. I'm shooting in the dark as far as running bundle install is concerned. I don't know if I'm supposed to run it as the same user as the Rails app or as the root user. Right now, I've been doing su - to change to root and then cd'ing to the Rails root directory and running bundle install. Not sure if this is the right way. Any help?

dan
  • 43,914
  • 47
  • 153
  • 254

3 Answers3

4

bundler's doc explicitly says don't do it as root:

http://gembundler.com/man/bundle-install.1.html

Quoted:

You should never use sudo bundle install. This is because several other steps in bundle install must be performed as the current user:

1) Updating your Gemfile.lock
2) Updating your vendor/cache, if necessary
3) Checking out private git repositories using your user's SSH keys

Especially true with RVM:

http://rvm.beginrescueend.com/rubies/rubygems/

Quoted:

DO NOT use sudo...

to work with RVM gems. When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. (You will start to think that someone has a voodoo doll of your application...)

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • Are you basically saying not to go the way of a system wide RVM installation? – dan Apr 05 '11 at 22:03
  • 1
    no no no, using RVM is great, and bundler is great, but just don't use `sudo` with them. – nonopolarity Apr 05 '11 at 22:11
  • 1
    Please see my new question http://stackoverflow.com/questions/5559188/is-a-system-wide-install-of-rvm-a-bad-idea – dan Apr 05 '11 at 22:19
  • If you have multi-user requirements, are savvy with bash, user permissions, users, and common server admin tasks, a system-wide install of RVM can be useful and easy (especially for a production server). I have found a nice way to do a system-wide install. The main thing is to not use the `sudo` command specifically. You should use `su --login ` instead. I've had success with installing RVM in `/opt/rvm`, setting up an `rvm` user with correct folder permissions on this dir, and then creating per-user gemsets with correct folder permissions so each user has control of their own gemset. – TrinitronX Jul 17 '12 at 21:34
  • re: first sentence of answer => not using sudo and not using root are not the same thing (as TrinitronX points out). That being said, using root and not using root has pro's and con's (but in general, more con's than pro's: a lot can be accomplished with dedicated no-login user admin accounts). But the point is that sudo should never be used, in any case, since the notion of "current user" gets messy when sudo'ing a script (including when the sudo'd script calls other scripts). – michael Oct 29 '12 at 00:28
3

bundle is smart. if your gems are in /usr/local or /opt or whatever and you don't have permissions, it will do this:

bundle install

<~/code/project> $ bundle install
Fetching https://github.com/plataformatec/simple_form.git
remote: Counting objects: 3275, done.
remote: Compressing objects: 100% (1225/1225), done.
remote: Total 3275 (delta 2289), reused 2836 (delta 1950)
Receiving objects: 100% (3275/3275), 369.42 KiB | 608 KiB/s, done.
Resolving deltas: 100% (2289/2289), done.
Fetching source index for http://rubygems.org/
Enter your password to install the bundled RubyGems to your system:
...

note the last line there... bundle runs sudo for you on just the stuff that needs root.

fringd
  • 2,380
  • 1
  • 18
  • 13
0

As whichever user owns and runs the ruby application.

Rein Henrichs
  • 15,437
  • 1
  • 45
  • 55