# Installing Ruby Application

**URL:** <https://www.ruby-forum.com/t/installing-ruby-application/182321>\
**Category:** Ruby\
**Created:** [January 26, 2010, 4:19pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321 "2010-01-26T16:19:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 26, 2010, 4:19pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/1 "2010-01-26T16:19:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 26, 2010, 4:40pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/2 "2010-01-26T16:40:59Z")

</div>

On Jan 26, 8:19 am, Tony M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 26, 2010, 4:49pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/3 "2010-01-26T16:49:11Z")

</div>

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/](http://www.erikveen.dds.nl/rubyscript2exe/)  
This could help.

Alternatively: Both the OneClickInstaller and the new [RubyInstaller.org](http://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:

> <https://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:

> **[Nullsoft Scriptable Install System](https://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System)**
>
> Nullsoft Scriptable Install System (NSIS) is a script-driven installer authoring tool for Microsoft Windows backed by Nullsoft, the creators of Winamp. NSIS is released under a combination of free software licenses, primarily the zlib license. It has become a widely used alternative to commercial proprietary products like InstallShield, with users including Amazon, Dropbox, Google, Ubisoft, FL Studio, BitTorrent, and McAfee.
> NSIS was created to distribute Winamp. It is based on a previous Null...

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

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.

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 26, 2010, 5:06pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/4 "2010-01-26T17:06:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 27, 2010, 1:03pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/5 "2010-01-27T13:03:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 28, 2010, 6:25am UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/6 "2010-01-28T06:25:23Z")

</div>

On Jan 26, 9:03 am, Phillip G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [January 27, 2010, 1:35pm UTC](https://www.ruby-forum.com/t/installing-ruby-application/182321/7 "2010-01-27T13:35:01Z")

</div>

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](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
