Alexander Shmatko Alexander Shmatko - 4 months ago 7x
Ruby Question

How to create a command that triggers executable file of your gem?

For example, I have a gem called mygem and I want to start executable file with a command


How can I do this?

enter image description here


Here is the RubyGems guide for how to add an executable.

The primary steps are:

  1. Add your script to the gem's /bin directory
  2. Your script must be executable in the filesystem chmod a+x bin/<yourfile>
  3. Make sure your script starts with a proper shebang
  4. Add the script to the .executables section of your gemspec

Note you will still have to build and install your gem locally to run the command without a path as you are trying to do in the screenshot.

More info in building executable gems.