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?
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...)
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.
As whichever user owns and runs the ruby application.
精彩评论