omarsafwany omarsafwany - 1 year ago 155
Ruby Question

Make ruby gem executable

I have built a ruby gem but I need to make it executable so it could be run from the terminal. I have googled and found that I need to make a file inside the

bin/
directory, require my library and then call whatever I need from it. Also I tried
chmod +x bin/myfile
to make it executable but nothing worked.Basically, I have followed this link but nothing worked.

In the bin directory, I have already a
console
and
setup
along with my newly created file which is as follows:

#!/usr/bin/env ruby

require "sys_libs"
s = SysLibs


Here's the
.gemspec
file:

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^bin/}) { |f| f[3..-1] }
spec.require_paths = ["lib"]


Anytime I try to change the executable, I get stuck with failed build. Any idea what else am I missing so far?

Answer Source

The spec.bindir = "exe" attribute should be spec.bindir = 'bin'.

spec.bindir        = 'bin'
spec.executables   = ['myfile']

Note that bindir is optional.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download