Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building gem, executable not found

Tags:

ruby

gem

I'm in the process of writing my first ruby gem and I'm a little new at the whole structure of setting up gems. My understanding from reading this guide is that in order to create an executable for my gem I need to do the following:

  1. Add a line to my gemspec specifiying the name of the executable like this:

    s.executables << 'gemname'

  2. Build the gem with

    gem build gemname.gemspec

  3. Install the gem locally (if you try to install by pushing to rubygems each time you'll end up having to change versions constantly) with

    gem install gemname-0.0.1.pre.gem

  4. Then test it out with

    gemname foo-arguments, --bar-options

If I go through all these steps then on #4 I get the following error:

$ gemname
zsh: command not found: gemname

Assuming that the executable a file starting with a shebang and located at gemname/bin/gemname

Everything works just fine if I navigate to the root of the gem folder and run bin/gemname to test out the executable.

Here is a gist of my current gemspec and the gem source is available on github here.

like image 548
Stephen Mariano Cabrera Avatar asked May 13 '15 15:05

Stephen Mariano Cabrera


2 Answers

You need to add all the files that need be included with the gem in spec.files. You missed to add the files that you have in the bin directory.

For example, I have the following configuration from one of my gems:

Gem::Specification.new do |spec|
  spec.files         = Dir["{bin,lib}/**/*", "LICENSE", "README.md"]
  spec.test_files    = Dir["spec/**/*"]
  spec.require_paths = ["lib"]
  spec.executables   = ["yarr"]
end
like image 62
Arturo Herrero Avatar answered Oct 06 '22 01:10

Arturo Herrero


Your gemspec is trying to change the load path. I would suggest fixing that first, because what you're reporting seems to be consistent with a gem not being able to find its files.

Look at your gemspec for this code:

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Then see http://guides.rubygems.org/patterns/

"Gems should not change the $LOAD_PATH variable. RubyGems manages this for you. Code like this should not be necessary ..."

See http://guides.rubygems.org/patterns/ for various solutions to load using the existing load path, and helpers such as require_relative.

like image 43
joelparkerhenderson Avatar answered Oct 05 '22 23:10

joelparkerhenderson