Ruby executable on ubuntu

Hi
I just wonderd if you guys know any way to execute a .rb file by
clicking on it.
For a while now I have used the terminal to run files, even with
graphics.

[email protected]: ruby /PATH TO FILE.rb

Any help would be great, I heard you can compile ruby with G++.

Can that be true?

It seems ridiculus to me.

:wink: THANKS

On 01/31/2012 07:11 PM, mark kirby wrote:

Hi
I just wonderd if you guys know any way to execute a .rb file by
clicking on it.
For a while now I have used the terminal to run files, even with
graphics.

[email protected]: ruby /PATH TO FILE.rb

This isn’t really a Ruby-specific issue but rather a Gnome issue.
Apparently, the only way to get the option to make the file association
to your Ruby interpreter is to create a .desktop file in
/usr/share/applications with the necessary details for Gnome to offer
Ruby as a potential application to open files. Assuming you have such a
.desktop file, you should be able to right click on the file and select
Ruby via the “Open With Other Application…” menu item.

Unfortunately, I don’t really have any experience with .desktop files.
I believe they are basically like INI files, and you can find some
examples already on your system under /usr/share/applications. Aside
from that, I can’t provide much better help than these links:

The spec: http://standards.freedesktop.org/desktop-entry-spec/latest/

Helpful tools:
http://mail.gnome.org/archives/desktop-devel-list/2002-May/msg00271.html

Any help would be great, I heard you can compile ruby with G++.

Can that be true?

It seems ridiculus to me.

Indeed, I have never heard of anyone directly compiling Ruby source into
native code using g++. I think I remember reading about a couple
projects a long time ago that would convert some subset of the Ruby
language into C code. Theoretically, you would be able to compile your
sources that way, but I don’t think those projects are still alive or
know if they even really worked at all.

-Jeremy

On 02/06/2012 09:59 AM, Adam Ms. wrote:

mark kirby wrote in post #1043353:

Hi
I just wonderd if you guys know any way to execute a .rb file by
clicking on it.

:wink: THANKS

Add a ruby shebang and chmod +x

This may not be the best possible solution unless you can safely rely on
the packaged Ruby versions included with Ubuntu. Given that there are
so many recommendations to install Ruby with RVM, especially on
distributions such as Ubuntu, adding a simple shebang line could be
problematic if you have more than a handful of files to run this way.
The problem is that if you change the Ruby you want to use later with a
new installation from RVM, you’ll have to update all those files to
point to the new installation in their shebang lines. However, if you
use the .desktop file approach, you only need to modify the single
.desktop file.

The .desktop approach has its own pitfalls, of course. One I can think
of off the top of my head is that all .rb files become effectively
executable whether you want to trust them to be so or not and whether
they are really application scripts or not.

Is there a way to set the shebang line to somehow reference RVM in such
a way that a simple file in the home directory could be used to
dynamically specify which of the RVM managed rubies should be used? I’m
thinking this would basically be like a user-level .rvmrc file. I
probably just need to read the RVM documentation to find that this does
exist, but if you had such a mechanism, you could safely skip .desktop
files entirely while still avoiding the need to mess with all your .rb
scripts in order to get them to run with the right Ruby.

-Jeremy

Jeremy B. wrote in post #1044360:

On 02/06/2012 09:59 AM, Adam Ms. wrote:

mark kirby wrote in post #1043353:

Hi
I just wonderd if you guys know any way to execute a .rb file by
clicking on it.

:wink: THANKS

Add a ruby shebang and chmod +x

This may not be the best possible solution unless you can safely rely on

-Jeremy

I think this will work with RVM on Ubuntu:

#!/usr/bin/env ruby

mark kirby wrote in post #1043353:

Hi
I just wonderd if you guys know any way to execute a .rb file by
clicking on it.

:wink: THANKS

Add a ruby shebang and chmod +x

On 02/06/2012 01:50 PM, Adam Ms. wrote:

Add a ruby shebang and chmod +x

This may not be the best possible solution unless you can safely rely on

I think this will work with RVM on Ubuntu:

#!/usr/bin/env ruby

It will only work when running from Nautilus or similar file browsing
program if you have arranged to select a Ruby with RVM during the
startup of your session; otherwise, the shebang above will either find
the system Ruby or fail if you don’t have one installed. In any case,
you cannot change the selected Ruby without restarting your session
because all of your programs will inherit the settings set at the
beginning of the session. In other words, you cannot start a terminal
and run RVM to change your Ruby selection for all programs in your
current session and then have Nautilus see that change.

Your suggestion will only really work for people running the scripts
from the command line (which is what I do on my Ubuntu systems), but
that’s not what the OP wanted to do. :slight_smile:

-Jeremy

Adam Ms. wrote in post #1044434:

rvm use 1.9.2-p180 do /home/adam/bin/test1.rb

I think this will work too:

bash -i -c “/home/adam/bin/test1.rb”

Jeremy B. wrote in post #1044412:

On 02/06/2012 01:50 PM, Adam Ms. wrote:

Add a ruby shebang and chmod +x

This may not be the best possible solution unless you can safely rely on

I think this will work with RVM on Ubuntu:

#!/usr/bin/env ruby

It will only work when running from Nautilus or similar file browsing

-Jeremy

Yes, you are correct!

How about this for the desktop launcher command line:

rvm use 1.9.2-p180 do /home/adam/bin/test1.rb

On 02/06/2012 04:53 PM, Adam Ms. wrote:

Adam Ms. wrote in post #1044434:

rvm use 1.9.2-p180 do /home/adam/bin/test1.rb

I think this will work too:

bash -i -c “/home/adam/bin/test1.rb”

It may work, but it would also cause the user’s .bashrc file to be
completely reloaded, which may be much more work than necessary. More
importantly, there is an implicit assumption that a particular Ruby is
selected in the .bashrc file. While that may be done by some people, it
seems unnecessary.

I think your earlier proposal is better all around. :slight_smile:

-Jeremy

On 02/06/2012 03:25 PM, Adam Ms. wrote:

Yes, you are correct!

How about this for the desktop launcher command line:

rvm use 1.9.2-p180 do /home/adam/bin/test1.rb

I think that might work. You would have to dynamically specify the file
to run, of course. I’m not sure how to do that, but I’m sure there must
be a way.

-Jeremy

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