best way to make .rb into an executable for linux?

D

David Ainley

I have a pretty basic .rb script that I would like to turn into an
executable. What is the best way to do this for Linux? I have no
intentions of cross compatibility, so I don't care if it won't work for
Windows or Mac.

I've tried rubyscript2exe. Doesn't work, but afaik, that's old so
whatevz.
I've tried to install crate via "gem install crate", but it gives me the
following error

Error installing crate:
ERROR: Failed to build gem native extension.


Can anyone give me a decent way to get a .rb to an executable for Linux?
(damn you ocra!)

Thanks guys.

wrinkliez
 
R

Rick DeNatale

I have a pretty basic .rb script that I would like to turn into an
executable. =A0What is the best way to do this for Linux? =A0I have no
intentions of cross compatibility, so I don't care if it won't work for
Windows or Mac.

I've tried rubyscript2exe. =A0Doesn't work, but afaik, that's old so
whatevz.
I've tried to install crate via "gem install crate", but it gives me the
following error

Error installing crate:
=A0ERROR: Failed to build gem native extension.


Can anyone give me a decent way to get a .rb to an executable for Linux?
(damn you ocra!)

Thanks guys.

In Posix systems executable doesn't necessarily mean a file has to be binar=
y.

Why not just put a shebang on the first line of the main file

#! /usr/bin/ruby

Check the actual path to put there by issuing the shell command which ruby

Then chmod the file to be executable.

You can optionally leave the .rb off the end of the file name, or symlink

e.g. if your main ruby file is

my_nifty_executable.rb

you could either rename it to just my_nifty_executable

or

ln -s my_nifty_executable.rb my_nifty_executable

--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 
D

David Ainley

I see. Well I could use that as a last resort I suppose, but won't the
user have to download the entire Ruby language and gems and whatnot if I
go that route? Certainly no problem, but it just seems unnecessary.

I appreciate the response though :)
 
B

Ben Bleything

I see. =A0Well I could use that as a last resort I suppose, but won't the
user have to download the entire Ruby language and gems and whatnot if I
go that route? =A0Certainly no problem, but it just seems unnecessary.

Yes, that's true. I think your best bet is going to be to figure out
why crate isn't working... does it give you any more output than you
pasted above?

Ben
 
C

Charles Oliver Nutter

FWIW, you can create a single-file executable (a jar file, basically,
run with java -jar jarfile.jar) with JRuby that runs anywhere Java's
installed and doesn't require any per-machine build or any other
dependencies to be installed (including JRuby itself). Might be an
easier path, if you're willing to use JRuby.
 
D

David Ainley

Ben said:
Yes, that's true. I think your best bet is going to be to figure out
why crate isn't working... does it give you any more output than you
pasted above?

Ben

The error is

ERROR: Failed to build gem native extension.

:S

And Charles, that's a good idea. Let me give that a try.
 
D

David Masover

Yes. They'll have to do that anyway. All of the solutions here revolve arou=
nd=20
making it easier for your users, but you're not likely to save much in term=
s=20
of bandwidth or disk space with any of these other approaches, unless I'm=20
missing something.
The error is
=20
ERROR: Failed to build gem native extension.

Are you sure that's it? Almost always, that error is followed by a large=20
amount of text which indicates the actual error.
And Charles, that's a good idea. Let me give that a try.

I don't know that this is necessarily better. It's a question of whether=20
they're more likely to have Ruby or Java installed. It might be easier to=20
manage with the gems, though...

If your target is Linux users, and gems aren't good enough, look at buildin=
g=20
debs, RPMs, or whatever your users actually expect. You might be able to=20
depend on the more popular gems as native packages, and you might combine t=
hat=20
with something like bundler to put anything missing into your package.

Of course, at this point, it might be getting a lot more complicated for yo=
u=20
than a JRuby jar, so I guess that's the advantage.

And of course, build a gem anyway, because that's easy, and because any new=
=20
solutions for building Ruby "executables" are likely to revolve around gems.
 
J

Jeremy Hinegardner

The error is

ERROR: Failed to build gem native extension.

This is probably a failure in building the amalgalite gem on your
system. Crate itself has no native extensions, but it does depend upon
amalgalite.

With crate, you would still have at least 2 files to ship to your end
user, the executable, and the sqlite database in which all the code
resides.

As the author of crate, I would not currently recommend it for
production use. It has been a while since I worked on it, and it
has not been kept up to date. I will eventually get back to working on
it when I have some copious free time. :)

enjoy,

-jeremy
 
R

Roger Pack

Charles said:
FWIW, you can create a single-file executable (a jar file, basically,
run with java -jar jarfile.jar) with JRuby that runs anywhere Java's
installed and doesn't require any per-machine build or any other
dependencies to be installed (including JRuby itself). Might be an
easier path, if you're willing to use JRuby.

Are there any step by step instructions on how to do that anywhere, by
chance?
-r
 
J

Jörg W Mittag

Roger said:
Are there any step by step instructions on how to do that anywhere, by
chance?

It's been several years since I last tried it, but IIRC it's basically

gem install rawr
cd /path/to/your/project
rawr install
# edit /path/to/your/project/build_configuration.rb
rake rawr:jar # create an executable jar file
rake rawr:bundle:exe # create a Windows executable
rake rawr:bundle:app # create an OSX app bundle

And that's more or less it.

Note that you will probably have to edit at least the c.source_dirs
configuration value, since Rawr generally assumes that you have a
mixed project and that your Ruby code lives under lib/ruby instead of
just lib. Other than that, you should be fine, Rawr will even
autodetect the c.project_name (I assume from the directory).

jwm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top