Weird rails error “permission denied: bin/rails” for old rails apps

天涯浪子 提交于 2019-11-29 06:21:18

问题


I'm getting this error whenever I run rails (or any rails command) _rails_command:2: permission denied: bin/rails ONLY when i'm inside some old rails app directory.

In these directories bundle exec rails c command works but rails or even rails -v don't work.

Background: I keep my coding workspace in dropbox folder. Now I recently installed Manjaro and hence all the rails apps which I downloaded back from my previous OS I call them old rails app.

In Short: Rails works fine everywhere except for old rails apps. bundle exec rails c works fine though. Ruby versions which I've tried: 2.0.0 (rvm), 2.1.1(rvm), 2.1.1 (system)

Gem Environment : RubyGems Environment: - RUBYGEMS VERSION: 2.2.2 - RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [x86_64-linux] - INSTALLATION DIRECTORY: /home/tat/.rvm/gems/ruby-2.0.0-p451@latest - RUBY EXECUTABLE: /home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/ruby - EXECUTABLE DIRECTORY: /home/tat/.rvm/gems/ruby-2.0.0-p451@latest/bin - SPEC CACHE DIRECTORY: /home/tat/.gem/specs - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /home/tat/.rvm/gems/ruby-2.0.0-p451@latest - /home/tat/.rvm/gems/ruby-2.0.0-p451@global - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - https://rubygems.org/ - SHELL PATH: - /home/tat/.rvm/gems/ruby-2.0.0-p451@latest/bin - /home/tat/.rvm/gems/ruby-2.0.0-p451@global/bin - /home/tat/.rvm/rubies/ruby-2.0.0-p451/bin - /home/tat/bin - /usr/local/bin - /usr/local/sbin - /usr/local/bin - /usr/bin - /usr/bin/core_perl - /home/tat/.rvm/bin

UPDATE: Its working fine in bash, the problem seem to be with oh-my-zsh.

Here is my rvm-info (from zsh):

ruby-2.0.0-p451@latest:

  system:
    uname:       "Linux tat-box 3.10.37-1-MANJARO #1 SMP Mon Apr 14 20:56:29 UTC 2014 x86_64 GNU/Linux"
    system:      "manjaro/0.8.9/x86_64"
    bash:        "/usr/bin/bash => GNU bash, version 4.3.8(1)-release (x86_64-unknown-linux-gnu)"
    zsh:         "/usr/bin/zsh => zsh 5.0.5 (x86_64-unknown-linux-gnu)"

  rvm:
    version:      "rvm 1.25.23 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "21 hours 33 minutes 15 seconds ago"
    path:         "/home/tat/.rvm"

  ruby:
    interpreter:  "ruby"
    version:      "2.0.0p451"
    date:         "2014-02-24"
    platform:     "x86_64-linux"
    patchlevel:   "2014-02-24 revision 45167"
    full_version: "ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]"

  homes:
    gem:          "/home/tat/.rvm/gems/ruby-2.0.0-p451@latest"
    ruby:         "/home/tat/.rvm/rubies/ruby-2.0.0-p451"

  binaries:
    ruby:         "/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/ruby"
    irb:          "/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/irb"
    gem:          "/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/gem"
    rake:         "/home/tat/.rvm/gems/ruby-2.0.0-p451@latest/bin/rake"

  environment:
    PATH:         "/home/tat/.rvm/gems/ruby-2.0.0-p451@latest/bin:/home/tat/.rvm/gems/ruby-2.0.0-p451@global/bin:/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin:/home/tat/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/home/tat/.gem/ruby/2.1.0/bin:/home/tat/.rvm/bin"
    GEM_HOME:     "/home/tat/.rvm/gems/ruby-2.0.0-p451@latest"
    GEM_PATH:     "/home/tat/.rvm/gems/ruby-2.0.0-p451@latest:/home/tat/.rvm/gems/ruby-2.0.0-p451@global"
    MY_RUBY_HOME: "/home/tat/.rvm/rubies/ruby-2.0.0-p451"
    IRBRC:        "/home/tat/.rvm/rubies/ruby-2.0.0-p451/.irbrc"
    RUBYOPT:      ""
    gemset:       "latest"

回答1:


In the directory you mentioned is your rails in executable mode. If not you can apply

chmod u+x bin/rails

and make it executable.




回答2:


Run

bundle exec rake rails:update:bin

It will update bin/rails and bin/rake files.




回答3:


I have this when I try to use a rails 4.0 version. So when I try to put bundle exec first, like:

bundle exec rake db:migrate

or

bundle exec rails s

work's.




回答4:


So what worked for me, anyone coming across this issue is to run

bundle exec rake app:update:bin

You'll be given a prompt asking if you want to overwrite? The options here are:

  • Y - yes (default one, just press Enter for it)
  • n - no (leave current file without changes)
  • a - all (apply all changes)
  • q - quit
  • d - diff
  • h - help

I chose a and it seemed to work ok.




回答5:


I had the same issue and here's what helped me. Open ~/.zshrc and add this

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"



回答6:


The solution for me was:

bundle exec rake rails:update:bin

or just use:

For new rails versions:

 bundle exec rake app:update:bin

For old rails versions:

bundle exec rake rails:update:bin


来源:https://stackoverflow.com/questions/23297832/weird-rails-error-permission-denied-bin-rails-for-old-rails-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!