25

When I run bundle exec rails console production or rails console production via SSH on the server in the Current folder of the Capistrano deploy I get:

Usage:
     rails new APP_PATH [options]

Options:
    (...)

with an explanation to start a new app. Locally it works. Why can't I start a console remotely?

user2609980
  • 10,264
  • 15
  • 74
  • 143

6 Answers6

64

I'm assuming that you updated to rails 4 from version 3 and your app can't find the executables in the bin directory. Run this to see your rails version:

$ rails -v

If your rails version is 4 or above, try running this:

$ rake rails:update:bin

Source: Rails 4 Release Notes

6.1 Notable changes

  • Your app's executables now live in the bin/ dir. Run rake rails:update:bin to get bin/bundle, bin/rails, and bin/rake.
  • I did not update Rails. It is a clean install. I will try to run the command anyway. – user2609980 Sep 07 '14 at 20:21
  • 1
    "bundle exec rake rails:update:bin" worked for me and then "bundle exec rails c" – RidingTheRails Mar 11 '15 at 16:24
  • I tried this solution but got the follwoing error: "No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)". I am new to ruby and rake. Any idea what's going on? – Lamar Jul 05 '16 at 22:59
  • I had to slightly alter the command to `bundle exec rake app:update:bin`. – johnrbnz Dec 30 '21 at 06:43
21

I am using capistrano to deploy, including the capistrano/bundler gem. Since the ./bin directory is version controlled in Rails 4, we need to prevent Capistrano from linking it on deployments by removing bin from set :linked_dirs.

Now in order to prevent bundler from overwriting the version controlled binstubs, we can add the line set :bundle_binstubs, nil which will prevent capistrano-bundler from setting the --binstubs option when running bundle install.

My config/deploy.rb file now has these lines:

# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

set :bundle_binstubs, nil

Note the lack of the bin directory in the :linked_dirs line.

Troy
  • 5,319
  • 1
  • 35
  • 41
15

I have the same problem, and turns out when you deploy through cap shared/bin is symlink to current/bin.

Here's what works for me:

  • rm current/bin
  • mkdir current/bin
  • rake rails:update:bin

This should help, but it is somewhat a temporary solution, I'm trying to find out how to make cap not auto symlink-ing current/bin.

maxhungry
  • 1,863
  • 3
  • 20
  • 28
9

In case of Rails 5.2

I had to remove bin directory by running below command in project root directory.

 rm -rf bin

and then I ran another command in project root directory:

 rake app:update:bin

It will show you output like below:

  create  bin
  create  bin/bundle
  create  bin/rails
  create  bin/rake
  create  bin/setup
  create  bin/update
  create  bin/yarn

That's it.

Manish Shrivastava
  • 30,617
  • 13
  • 97
  • 101
0

It's been a little while since this was answered.

In my case I needed to run:

rake app:update:bin

Note- app rather than rails.

I was missing the bin directory all-together in my Rails 5.1 App

Smithy
  • 5
  • 3
0

I faced this issue on my production server when I updated my application from Rails 5.2 to 6.0.4. Simply follow these steps:

cd to_your_project_dir
rm -r bin
rake app:update:bin
the Tin Man
  • 158,662
  • 42
  • 215
  • 303