/usr/bin/env ruby 没有这样的文件或目录:使用 capistrano 3、capistrano/rbenv、capistrano/bundler 和 capistrano/rails(使用 rails 4)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19716131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/usr/bin/env ruby no such file or directory: Using capistrano 3, capistrano/rbenv, capistrano/bundler and capistrano/rails (using rails 4)
提问by patriciomacadden
I'm using capistrano, capistrano/rbenv, capistrano/bundler and capistrano/rails. I get this error in the step where capistrano compiles the assets:
我正在使用 capistrano、capistrano/rbenv、capistrano/bundler 和 capistrano/rails。我在 capistrano 编译资产的步骤中收到此错误:
DEBUG [49a50df6] /usr/bin/env:
DEBUG [49a50df6] ruby
DEBUG [49a50df6] : No such file or directory
DEBUG [49a50df6]
In the production server /usr/bin/env ruby -vis correct.
I'm aware of this: why-does-something-work-in-my-ssh-session-but-not-in-capistranoBut I can't get it to work.
在生产服务器中/usr/bin/env ruby -v是正确的。我知道这一点:why-does-some-work-in-my-ssh-session-but-not-in-capistrano但我无法让它工作。
This is my Capfile:
这是我的Capfile:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails/tree/master/assets
# https://github.com/capistrano/rails/tree/master/migrations
#
# require 'capistrano/rvm'
require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
This is my deploy.rb:
这是我的deploy.rb:
# rbenv
set :rbenv_type, :user
set :rbenv_ruby, '2.0.0-p247'
# bundler
set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_flags, '--deployment --quiet'
set :bundle_without, %w{development test}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
set :bundle_roles, :all
# rails
set :rails_env, 'production'
set :application, 'MY APP'
set :repo_url, 'MY_REPO.git'
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# set :deploy_to, '/var/www/my_app'
# set :scm, :git
# set :format, :pretty
# set :log_level, :debug
# set :pty, true
set :linked_files, %w{.env config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after :finishing, 'deploy:cleanup'
end
And this is my staging.rb:
这是我的staging.rb:
set :stage, :staging
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
#role :app, %w{[email protected]}
#role :web, %w{[email protected]}
#role :db, %w{[email protected]}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a has can be used to set
# extended properties on the server.
#server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
server 'my_server', user: 'my_user', roles: %w{web app db}
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
# and/or per server
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
# setting per server overrides global ssh_options
# fetch(:default_env).merge!(rails_env: :staging)
set :deploy_to, '/home/my_user'
And this is the full trace:
这是完整的跟踪:
INFO [c24b8f94] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p247 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on 162.243.16.201
DEBUG [c24b8f94] Command: cd /home/my_app/releases/20131101193513 && ( RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p247 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG [c24b8f94] /usr/bin/env:
DEBUG [c24b8f94] ruby
DEBUG [c24b8f94] : No such file or directory
DEBUG [c24b8f94]
cap aborted!
rake stdout: Nothing written
rake stderr: Nothing written
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/command.rb:94:in `exit_status='
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:147:in `block (2 levels) in _execute'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:149:in `block in _execute'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-rails-1.0.0/lib/capistrano/tasks/assets.rake:61:in `block (6 levels) in <top (required)>'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/abstract.rb:89:in `with'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-rails-1.0.0/lib/capistrano/tasks/assets.rake:60:in `block (5 levels) in <top (required)>'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/abstract.rb:81:in `within'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-rails-1.0.0/lib/capistrano/tasks/assets.rake:59:in `block (4 levels) in <top (required)>'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `run'
/Users/patricio/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sshkit-1.1.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:assets:precompile
By the way, I think it's not related to $PATH, because bundle installruns just fine.
顺便说一句,我认为它与 无关$PATH,因为bundle install运行得很好。
Does anyone know what's going on?
有谁知道发生了什么?
Thank you!
谢谢!
采纳答案by patriciomacadden
Ok, fixed it.
好的,修好了。
I added this:
我加了这个:
set :default_env, { path: "~/.rbenv/shims:~/.rbenv/bin:$PATH" }
to my deploy.rb.
到我的deploy.rb.
I'm not sure is the best solution, but it worked.
我不确定是最好的解决方案,但它奏效了。
回答by Langusten Gustel
Okay, as I had the same issue and it took me quite a while to resolve it:
好的,因为我遇到了同样的问题,我花了很长时间才解决它:
You are probably wondering why this command is not working while it IS working when you log into with you shell using ssh.
当您使用 ssh 登录 shell 时,您可能想知道为什么此命令在运行时不起作用。
I am not an expert (so correct me when I am wrong): The thing is there are several differences in logging in on a remote server using ssh. To quote the documentation of capistrano:
我不是专家(所以在我错的时候纠正我):问题是使用 ssh 登录远程服务器有几个不同之处。引用 capistrano 的文档:
It's really a question of which kind of shell Capistrano is using, it's a matrix of possibilities concerning login, non-login, interactive, or non-interactive.
这实际上是 Capistrano 使用哪种外壳的问题,它是有关登录、非登录、交互或非交互的可能性矩阵。
They have a fancy graphic here(at the bottom) where they illustrate the path of files that are executed in login process. - the given source is also interesting if you want to continue reading on this topic.
他们在这里(底部)有一个精美的图形,其中说明了在登录过程中执行的文件的路径。-如果您想继续阅读该主题,给定的来源也很有趣。
What is going wrong?
出了什么问题?
When YOU log in using ssh you are (on login) executing several files (for example .bash_profile when you using the bash). Commonly your $PATH variable is extended with several paths to important functions in your envirement. BUT different login "styles" include different files.
当您使用 ssh 登录时,您(登录时)正在执行多个文件(例如,使用 bash 时的 .bash_profile)。通常,您的 $PATH 变量会扩展到您环境中重要功能的多个路径。但是不同的登录“样式”包含不同的文件。
As the documentation says again:
正如文档再次所说:
By default Capistrano always assigns a non-login, non-interactive shell.
默认情况下,Capistrano 总是分配一个非登录、非交互式 shell。
In my case this lead to a case where my login file .bash_profile is not included BUT it included the settings for my rvm. The result that the capistrano login session didnt know about my rvm path.
在我的情况下,这导致我的登录文件 .bash_profile 不包含但它包含我的 rvm 设置的情况。capistrano 登录会话不知道我的 rvm 路径的结果。
How can I fix this?
我怎样才能解决这个问题?
For me it turned out to just be the uncommentingof the require 'capistrano/rvm'(As I am using RVM) line in the Capfile(located in the root of your rails-project.
对我来说,它竟然只是该取消注释的需要“Capistrano的/ RVM”(由于我使用RVM)在该行Capfile(位于轨项目的根。
Hope to help someone.
希望能帮助某人。
EDIT:
编辑:
And for sure include gem 'capistrano-rvm'in the Gemfile!
并且肯定包含gem 'capistrano-rvm'在 Gemfile 中!
回答by ethan
I think you should execute
我认为你应该执行
apt-get install git-core
at your server
在您的服务器上
回答by BravoKing
I had the same problem using rbenv. What solved it for me was including the rbenv library before bundler--not after it. The order turned out to be important. Here's what's in my Capfile:
我在使用 rbenv 时遇到了同样的问题。为我解决的是在 bundler 之前包含 rbenv 库——而不是在它之后。结果证明这个顺序很重要。这是我的 Capfile 中的内容:
require 'capistrano/rbenv'
require 'capistrano/bundler'
If you did it right you should see the bundle command executed with the rbenv prefix, along these lines:
如果你做对了,你应该会看到使用 rbenv 前缀执行的 bundle 命令,如下所示:
XX RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.3.0 $HOME/.rbenv/bin/rbenv exec bundle install ...
回答by Kir
Make sure you are requiring all of these gems in your Capfile.
确保您的 Capfile 中需要所有这些 gem。
回答by Dilshad PT
Solution to ERROR:
错误的解决方法:
/usr/bin/env git no such file or directory capistrano
/usr/bin/env git 没有这样的文件或目录 capistrano
Install git in remote server, machine to which deployment is to be done.
在远程服务器上安装 git,即要完成部署的机器。
apt-get install git
回答by hjijin
My problem is:
我的问题是:
DEBUG [3132b2c2] /usr/bin/env: ‘bundle': No such file or directory
DEBUG [3132b2c2]
I solved it this way:
我是这样解决的:
In Debian, there is a block of code in your ~/.bashrc that says:
在 Debian 中,您的 ~/.bashrc 中有一个代码块,上面写着:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
When you run Capistrano, it will actually use your ~/.bashrc but it will not run any command below that block of code.
当您运行 Capistrano 时,它实际上会使用您的 ~/.bashrc 但它不会在该代码块下运行任何命令。
So, I fixed the problem adding the lines of code that were required by load ruby environment above that block of code, so Capistrano could load bundle.
因此,我解决了在该代码块上方添加加载 ruby 环境所需的代码行的问题,因此 Capistrano 可以加载 bundle。
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
PS:I use chruby in my server.
PS:我在我的服务器中使用 chruby。
回答by Is Ma
When I typed bundle installinteractively on a Terminal, it worked. Now, when I use it through Capistrano, it doesn't work.
当我bundle install在终端上交互式输入时,它起作用了。现在,当我通过 Capistrano 使用它时,它不起作用。
I solved it this way:
我是这样解决的:
In Ubuntu, there is a block of code in your ~/.bashrcthat says:
在 Ubuntu 中,您的代码块中~/.bashrc写着:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
When you run Capistrano, it will actually use your ~/.bashrcbut it will notrun any command below that block of code.
当您运行 Capistrano 时,它实际上会使用您的~/.bashrc但不会运行该代码块下方的任何命令。
So, I fixed the problem moving the lines of code that were required by bundle installabovethat block of code, so Capistrano could load them.
因此,我解决了移动该代码块bundle install上方所需的代码行的问题,因此 Capistrano 可以加载它们。
You could get a hint of which lines to move by running which bundle.
您可以通过运行获得有关要移动哪些行的提示which bundle。
回答by Milind
I was facing the same error.After trying hard to resolve it, i remembered that i have removed few packages randomly from my server where i was deploying the code.
我遇到了同样的错误。在努力解决之后,我记得我从部署代码的服务器中随机删除了几个包。
So i also removed git accidently.Running sudo apt-get install gitfixed it .
所以我也意外删除了 git。Runningsudo apt-get install git修复了它。

