x-yuri
x-yuri

Reputation: 18863

What adds bin dir of a rails app?

I can run rails with bundle exec rails, can't I? What's the difference between this and bin/rails then? There's also bundler's binstubs feature, which makes things even more complex. Briefly, which way should I run executables of a rails app, and why?

Upvotes: 1

Views: 76

Answers (1)

wpp
wpp

Reputation: 7303

https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

Preface, emphasises mine:

When you run rspec within your project’s directory, rbenv can ensure that it will get executed with the Ruby version configured for that project. However, nothing will ensure that the right version of RSpec gets activated; in fact, RubyGems will simply activate the latest RSpec version even if your project depends on an older version. In the context of a project, this is unwanted behavior.

This is why bundle exec is so essential. It ensures the right versions of dependencies get activated, ensuring a consistent ruby runtime environment. However, it's a pain to always have to write bundle exec.

To answer your question: "I can run rails with bundle exec rails, can't I? What's the difference between this and bin/rails then?"

(from the same guide)

bundle exec is so often needed. It ensures the right versions of dependencies get activated, ensuring a consistent ruby runtime environment. However, bundle exec is a pain to always have to write.

This is where "bundlers binstubs feature" comes in:

Bundler can install binstubs for executables contained in your project's bundle:

bundle install --binstubs

RSpec can now be easily run with just bin/rspec

"which way should I run executables of a rails app, and why?"

You are encouraged to check these binstubs in the project's version control so your colleagues might benefit from them.

Upvotes: 3

Related Questions