Installing Ruby Application

What’s the best way to install a Ruby (non-rails) application?

So far I’ve built and written a launchable gem on my Mac. There’s a
script, /lib/appname.rb that does everything. When I install the gem
(which works like a charm) on a WIN machine, the user has to open a cmd
window and launch C:\Ruby\lib\ruby\gems\1.8\gems\appname\lib\appname.rb
plus arguments, which I think is pretty ugly.

I’ve tried adding a launcher script into /bin and adding it to the
gemspec like this

spec = Gem::Specification.new do |s|
s.name = ‘appname’
s.version = ‘0.0.3’
s.summary = ‘desc’
s.description = %{desc}
s.test_files = Dir[‘test/*.rb’]
s.bindir = ‘bin’

However, the files I put in /bin don’t seem to be installed to
c:\Ruby\bin as I would expect it, when I unpack it, they’re not even
included.

I’m clueless on how I can make this a bit more userfriendly.

Any help is much appreciated.

Thanks,
Tony

On Jan 26, 8:19 am, Tony M. [email protected] wrote:

I’ve tried adding a launcher script into /bin and adding it to the
gemspec like this

spec = Gem::Specification.new do |s|
s.name = ‘appname’
s.version = ‘0.0.3’
s.summary = ‘desc’
s.description = %{desc}
s.test_files = Dir[‘test/*.rb’]
s.bindir = ‘bin’

You also need to specify the executable(s) inside the bindir that you
want installed:

s.executables << ‘my_app_name’

You don’t even need it to have a .rb extension if you have a shebang
line at the top.
(Even works on Windows.)
#!/usr/bin/env ruby -KU

On 26.01.2010 16:19, Tony M. wrote:

What’s the best way to install a Ruby (non-rails) application?

So far I’ve built and written a launchable gem on my Mac. There’s a
script, /lib/appname.rb that does everything. When I install the gem
(which works like a charm) on a WIN machine, the user has to open a cmd
window and launch C:\Ruby\lib\ruby\gems\1.8\gems\appname\lib\appname.rb
plus arguments, which I think is pretty ugly.

I’m clueless on how I can make this a bit more userfriendly.

http://www.erikveen.dds.nl/rubyscript2exe/
This could help.

Alternatively: Both the OneClickInstaller and the new RubyInstaller.org
register both the .rb and .rbw extensions with ruby.exe and rubyw.exe,
respectively.

Calling just the script launches Ruby. In the first case, with command
line, in the second case without command line.

So, just create an installer that packages your application, writes
files to the necessary locations, creates Start Menu entries, and
creates an uninstaller. We Windows user expect all that.

Registry keys to look for:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\RubyFile\shell\open # CLI Ruby
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\RubyWFile\shell\open # “headless”
Ruby

You can also take a look at the InnoSetup files of the RubyInstaller
project:
http://github.com/oneclick/rubyinstaller/blob/master/resources/installer/rubyinstaller.iss

Alas, Ruby doesn’t create its own Registry hive, so you cannot check for
the Ruby version with any ease (I’ll file a feature request for that).

NSIS is an OSS installer package:
http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System

Alas, you’ll have to compile it yourself on MacOS X, but maybe somebody
else already did that for you. :slight_smile:

If you don’t want to rely on a particular Ruby version, but rather
provide your own, just include one in your install package. Keep in
mind, you’ll have to keep track of dependencies yourself, since you
cannot use RubyGems’ dependency tracking.

On 26.01.2010 16:40, Phrogz wrote:

You don’t even need it to have a .rb extension if you have a shebang
line at the top.
(Even works on Windows.)
#!/usr/bin/env ruby -KU

No, it doesn’t.

PS C:\Scripts> .\shebang.ext # Pops up Windows’ unknown filetype dialog
PS C:\Scripts> cat .\shebang.ext
#!/usr/bin/env ruby -KU

puts “hello world”
PS C:\Scripts>
PS C:\Scripts> mv .\shebang.ext .\shebang.rb
PS C:\Scripts> .\shebang.rb
hello world
PS C:\Scripts>

Ruby’s installers register the .rb[w] extension with Windows, however.

Gavin K. wrote:

You also need to specify the executable(s) inside the bindir that you
want installed:

s.executables << ‘my_app_name’

Thanks Gavin! That one actually did it! All I had to do from there was
write a launcher script that would lauch the application from /lib so I
called

require “#{File.dirname(FILE)}/…/lib/appname”

and instantiated the main class - et voila!

Phillip: I also toyed around with rubyscript2exe because it seems very
appealing. In the end I couldn’t figure out how to easily include
additional files (I need to deploy some graphics with the application) -
the gem, however, easily allows for that.

Hey - thanks again - you saved me from another day of bad headaches!

Cheers,
Tony

On Jan 26, 9:03 am, Phillip G. [email protected] wrote:

On 26.01.2010 16:40, Phrogz wrote:

You don’t even need it to have a .rb extension if you have a shebang
line at the top.
(Even works on Windows.)
#!/usr/bin/env ruby -KU

No, it doesn’t.
[snip[
Ruby’s installers register the .rb[w] extension with Windows, however.

Ah, silly me, right you are. I was confused because I have an
executable without a .rb extension and it ‘just worked’ when I
installed the gem. I misattributed it to some shebang line magic
somewhere. In fact, the rubygems install process creates a .bat file
in the ruby bin directory with the name of your executable, and hence
you can just type “mycommand” at a Windows prompt and it will work.

The shebang line is still a good idea, but wholly unrelated to why you
can create a ‘binary’ command without a .rb extension in a gem and
have it work on Windows.

Tony M. wrote:

Phillip: I also toyed around with rubyscript2exe because it seems very
appealing. In the end I couldn’t figure out how to easily include
additional files (I need to deploy some graphics with the application) -
the gem, however, easily allows for that.

rubyscript2exe isn’t actually maintained (actually means since 2007).
Use ocra instead: http://www.gemcutter.org/gems/ocra

As far as I know, you can’t include files like graphics in an executable
(except DLLs). You’ll have to provide them extra, maybe in a
subdirectory of your application.

Marvin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs