/usr/bin/env ruby no such file or directory: Using capistrano 3, capistrano/rbenv, capistrano/bundler and capistrano/rails (using rails 4)

patriciomacadden

I'm using capistrano, capistrano/rbenv, capistrano/bundler and capistrano/rails. I get this error in the step where capistrano compiles the assets:

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 -v is correct. I'm aware of this: why-does-something-work-in-my-ssh-session-but-not-in-capistrano But I can't get it to work.

This is my 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:

# 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:

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 install runs just fine.

Does anyone know what's going on?

Thank you!

patriciomacadden

Ok, fixed it.

I added this:

set :default_env, { path: "~/.rbenv/shims:~/.rbenv/bin:$PATH" }

to my deploy.rb.

I'm not sure is the best solution, but it worked.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

"bin/rails: No such file or directory" w/ Ruby 2 & Rails 4 on Heroku

From Dev

Capistrano 3 deployment for Rails 4 binstubs conflict?

From Dev

Rails 4 API deployment example to Amazon EC2 using Capistrano 3, Nginx, Puma, GitHub, and RVM?

From Dev

Using Roadie 3 With Rails 4

From Dev

Ruby on Rails whenever + capistrano v3 integration

From Dev

Using bitly in Ruby on Rails

From Dev

Trouble using capistrano 3 while deploying

From Dev

Ruby on Rails: Capistrano 3 deployment error

From Dev

capistrano not using rails environment with bundler properly

From Dev

Using Ruby to find a file with changing directory

From Dev

Ruby deploy to localhost using Capistrano issue

From Dev

Airbrake integration with Capistrano 3 with Rails 4 getting LoadError: cannot load such file -- airbrake/capistrano3

From Dev

Ruby on Rails 4 - Using Rake on Heroku

From Dev

Skip database migration while deploying Rails application using Capistrano 3

From Dev

"Please require this file from within a Capistrano recipe" error while deploying Rails 3 app on EC2 using Capistrano

From Dev

Failed to load libmysql.dll file using Ruby on Rails 3

From Dev

Using :owner in Ruby on Rails

From Dev

Generate WAR file for Ruby on Rails using JRuby

From Dev

deploy rails app using capistrano or aws opsworks?

From Dev

bundle error in deploying rails using capistrano

From Dev

Ruby on Rails whenever + capistrano v3 integration

From Dev

Trouble using capistrano 3 while deploying

From Dev

Ruby On Rails: How to write yml configurations in a file when deploying with Capistrano 3?

From Dev

chef rails 4 ruby 2.1 rbenv capistrano shared bin passenger file missing

From Dev

Ruby on rails 4.1.6 + Capistrano 3: purge gems on deployment server

From Dev

Airbrake integration with Capistrano 3 with Rails 4 getting LoadError: cannot load such file -- airbrake/capistrano3

From Dev

No images and fonts production using Capistrano and Rails

From Dev

Rails 4, Capistrano 3 and Dotenv - How to deploy using server-side .env file

From Dev

Using Carrierwave and Capistrano with Rails

Related Related

  1. 1

    "bin/rails: No such file or directory" w/ Ruby 2 & Rails 4 on Heroku

  2. 2

    Capistrano 3 deployment for Rails 4 binstubs conflict?

  3. 3

    Rails 4 API deployment example to Amazon EC2 using Capistrano 3, Nginx, Puma, GitHub, and RVM?

  4. 4

    Using Roadie 3 With Rails 4

  5. 5

    Ruby on Rails whenever + capistrano v3 integration

  6. 6

    Using bitly in Ruby on Rails

  7. 7

    Trouble using capistrano 3 while deploying

  8. 8

    Ruby on Rails: Capistrano 3 deployment error

  9. 9

    capistrano not using rails environment with bundler properly

  10. 10

    Using Ruby to find a file with changing directory

  11. 11

    Ruby deploy to localhost using Capistrano issue

  12. 12

    Airbrake integration with Capistrano 3 with Rails 4 getting LoadError: cannot load such file -- airbrake/capistrano3

  13. 13

    Ruby on Rails 4 - Using Rake on Heroku

  14. 14

    Skip database migration while deploying Rails application using Capistrano 3

  15. 15

    "Please require this file from within a Capistrano recipe" error while deploying Rails 3 app on EC2 using Capistrano

  16. 16

    Failed to load libmysql.dll file using Ruby on Rails 3

  17. 17

    Using :owner in Ruby on Rails

  18. 18

    Generate WAR file for Ruby on Rails using JRuby

  19. 19

    deploy rails app using capistrano or aws opsworks?

  20. 20

    bundle error in deploying rails using capistrano

  21. 21

    Ruby on Rails whenever + capistrano v3 integration

  22. 22

    Trouble using capistrano 3 while deploying

  23. 23

    Ruby On Rails: How to write yml configurations in a file when deploying with Capistrano 3?

  24. 24

    chef rails 4 ruby 2.1 rbenv capistrano shared bin passenger file missing

  25. 25

    Ruby on rails 4.1.6 + Capistrano 3: purge gems on deployment server

  26. 26

    Airbrake integration with Capistrano 3 with Rails 4 getting LoadError: cannot load such file -- airbrake/capistrano3

  27. 27

    No images and fonts production using Capistrano and Rails

  28. 28

    Rails 4, Capistrano 3 and Dotenv - How to deploy using server-side .env file

  29. 29

    Using Carrierwave and Capistrano with Rails

HotTag

Archive