简体   繁体   中英

Ruby on Rails: Why do I have to use sudo for commands to succede?

I'm learning ruby on rails... I've was able to install an app on my OSX (10.8.3) localhost but it was very problematic most commands failed with permission-related errors unless I used sudo:

$ refinerycms ./

$ bundle install

$ bundle update

$ rails server

All off these fail without sudo... and I'm not sure why. It's somewhat of a hassle to do, but more importantly it seems like I must have done something wrong during set-up for this to be happening. Does anyone know what I did wrong and how to fix it?

Update I suspect this might be relevant: (Notice that both point to the same place.)

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.4.0]
  - INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p194
  - RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p194/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /usr/local/rvm/gems/ruby-1.9.3-p194
     - /usr/local/rvm/gems/ruby-1.9.3-p194@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/


$ sudo gem environment
Password:
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.4.0]
  - INSTALLATION DIRECTORY: /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/rvm/rubies/ruby-1.9.3-p194/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1
     - /Users/ESL/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

This may or may not be related to the fact that ~/.rvm does not exist. It doesn't appear .rvm exists anywhere.

Update 2 I don't know much about rails apps but I noticed that certain files appear to be owned by the system and not my user. Is that normal?

Update 3 My hunch is that all my gems are associated with root, not my user, which would explain why I keep getting permissions errors every time I try to do things. So I tried reinstalling rvm as a user...

$ \curl -L https://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   184  100   184    0     0    192      0 --:--:-- --:--:-- --:--:--   223
100 13641  100 13641    0     0   9060      0  0:00:01  0:00:01 --:--:--  9060
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   124  100   124    0     0    381      0 --:--:-- --:--:-- --:--:--   475
100 3263k  100 3263k    0     0   536k      0  0:00:06  0:00:06 --:--:--  615k

Upgrading the RVM installation in /usr/local/rvm/
    RVM PATH line found in /Users/ESL/.bashrc /Users/ESL/.zshrc.
    RVM sourcing line found in /Users/ESL/.bash_profile /Users/ESL/.zprofile.

Upgrade Notes:


  * WARNING: you have 'rvm_configure_env' in /etc/rvmrc, run the following to fix:

      sudo sed -i'' -e "/rvm_configure_env=.*\/opt\/sm/d" /etc/rvmrc
      rvm autolibs smf

  * No new notes to display.

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues run 'rvm requirements' or read 'rvm notes'

Upgrade of RVM in /usr/local/rvm/ is complete.

#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and
#   more enjoyable!!!
#
# ~Wayne

It seems to have worked, but it looks to me like it keeps landing in the root instead of /Users/ME. Am I onto something?

update

$ \curl -L https://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   184  100   184    0     0    124      0  0:00:01  0:00:01 --:--:--   143
100 13641  100 13641    0     0   6907      0  0:00:01  0:00:01 --:--:--  6907
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   124  100   124    0     0    561      0 --:--:-- --:--:-- --:--:--   712
100 3263k  100 3263k    0     0   767k      0  0:00:04  0:00:04 --:--:--  907k

Installing RVM to /usr/local/rvm/
    RVM PATH line found in /Users/ESL/.bashrc /Users/ESL/.zshrc.
    RVM sourcing line found in /Users/ESL/.bash_profile /Users/ESL/.zprofile.

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues run 'rvm requirements' or read 'rvm notes'

Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /usr/local/rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and
#   more enjoyable!!!
#
# ~Wayne

You installed RVM incorrectly, which is easy to do. "This usually is because people execute the install as root, rather than executing the installation instructions from a non-privileged user account." I suggest removing RVM entirely with sudo rvm implode and installing it again in single-user mode. Run as you, not root, not sudo:

\curl -L https://get.rvm.io | bash -s stable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM