I can use gems like RSpec or Rails or Pry by calling their respective gem names, e.g. rspec
, rails
, pry
on the commandline. How can I achieve this with gems I create? I'm using bundler for the basic gem creation.
To make your gem executable in CLI, you should set the followings up.
bin
folder, like bin/hello
chmod u+x bin/hello
)hello.gemspec
)spec.files = `git ls-files -Z`.split("\x0")
spec.bindir = 'bin'
spec.executables << 'hello'
spec.executables
considers bin
as default folder for binaries and executables, though you can change it.
You can find documentation about this here: Gemspec#executables.
According to documentation of Gemspec file you must put your executable in bin/
folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With