Forum: Ruby Ruby 1.9.3-p362 on Mac OSX

Posted by Peter Bailey (peterbailey)
on 2013-02-06 15:30
Hi,
I've installed the latest Ruby on my Mac using Homebrew. When I type
"which Ruby" I get this:

/Users/peterbailey/.rvm/rubies/ruby-1.9.3-p362/bin/ruby

But, I can't use that as a shebang in my Ruby scripts. Can someone tell
me what I should use as a shebang in my Ruby scripts? None of these
work.

#!/usr/bin/env ruby
#!/usr/bin/ruby
#!/usr/local/bin/ruby


Thanks,
Peter
Posted by Jon Cairns (jonathan_c)
on 2013-02-06 16:41
(Received via mailing list)
The following:

    /usr/bin/env ruby

should work, so it sounds like your $PATH environment variable doesn't
contain the rvm bin path. Try running:

    source "$HOME/.rvm/scripts/rvm"

That should do the trick for your current shell session, but you can add 
it
to your .bashrc/.bash_profile to set up the environment variable each 
time
you open your terminal. Hope that helps.
Posted by Peter Bailey (peterbailey)
on 2013-02-06 16:48
Jon Cairns wrote in post #1095548:
> The following:
>
>     /usr/bin/env ruby
>
> should work, so it sounds like your $PATH environment variable doesn't
> contain the rvm bin path. Try running:
>
>     source "$HOME/.rvm/scripts/rvm"
>
> That should do the trick for your current shell session, but you can add
> it
> to your .bashrc/.bash_profile to set up the environment variable each
> time
> you open your terminal. Hope that helps.

Thanks, Jon.
Well, here's what I have in my bash profile. I believe it was put in 
there when I installed dvm

    if [[ -s $HOME/.rvm/scripts/rvm ]]; then
      source $HOME/.rvm/scripts/rvm;

Is that doing exactly the same thing that you had me do above?

I just put "#!/usr/bin/env ruby"  into one of my Ruby scripts now. I 
tried to run it and it says:

env: ruby\r: No such file or directory
Posted by Jon Cairns (jonathan_c)
on 2013-02-06 16:53
(Received via mailing list)
On 6 February 2013 15:48, Peter Bailey <lists@ruby-forum.com> wrote:

> tried to run it and it says:
>
> env: ruby\r: No such file or directory


Strange. What does your $PATH environment variable contain?

    $ echo $PATH
Posted by Peter Bailey (peterbailey)
on 2013-02-06 16:56
Jon Cairns wrote in post #1095551:
> On 6 February 2013 15:48, Peter Bailey <lists@ruby-forum.com> wrote:
>
>> tried to run it and it says:
>>
>> env: ruby\r: No such file or directory
>
>
> Strange. What does your $PATH environment variable contain?
>
>     $ echo $PATH

My path is:

/Users/peterbailey/documents/scripts/ruby/local:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/users/peterbailey/documents/scripts/ruby/local:/opt/X11/bin:/usr/local/git/bin:
Posted by Hassan Schroeder (Guest)
on 2013-02-06 17:17
(Received via mailing list)
On Wed, Feb 6, 2013 at 7:48 AM, Peter Bailey <lists@ruby-forum.com> 
wrote:

> I just put "#!/usr/bin/env ruby"  into one of my Ruby scripts now. I
> tried to run it and it says:
>
> env: ruby\r: No such file or directory

? Did you copy/paste that from somewhere? That \r looks out of
place.

08:11 ~ $ cat bar
#!/usr/bin/env foo

WAT
08:11 ~ $ ./bar
env: foo: No such file or directory
08:11 ~ $
Posted by Jon Cairns (jonathan_c)
on 2013-02-06 17:18
(Received via mailing list)
> My path is:
>
> /Users/peterbailey/documents/scripts/ruby/local:/usr/local/
bin:/usr/bin:/bin:/usr/sbin:/sbin:/users/peterbailey/
documents/scripts/ruby/local:/opt/X11/bin:/usr/local/git/bin:

Yeh, your ruby path hasn't been included in that. You want to be seeing
"/Users/peterbailey/.rvm/rubies/ruby-1.9.3-p362/bin" somewhere in there.

Try sourcing ~/.rvm/environments/default - I've found that it's 
sometimes
necessary (when it's a full moon, for instance):

    $ source "$HOME/.rvm/environments/default"

Then check your $PATH again and see whether it's added your rubies bin
directory.
Posted by Peter Bailey (peterbailey)
on 2013-02-06 17:26
Jon Cairns wrote in post #1095559:
>> My path is:
>>
>> /Users/peterbailey/documents/scripts/ruby/local:/usr/local/
> bin:/usr/bin:/bin:/usr/sbin:/sbin:/users/peterbailey/
> documents/scripts/ruby/local:/opt/X11/bin:/usr/local/git/bin:
>
> Yeh, your ruby path hasn't been included in that. You want to be seeing
> "/Users/peterbailey/.rvm/rubies/ruby-1.9.3-p362/bin" somewhere in there.
>
> Try sourcing ~/.rvm/environments/default - I've found that it's
> sometimes
> necessary (when it's a full moon, for instance):
>
>     $ source "$HOME/.rvm/environments/default"
>
> Then check your $PATH again and see whether it's added your rubies bin
> directory.

OK. Did that. And, yes, now I see that Ruby directory in my path, first 
thing in fact. But, I'm still getting "env: ruby\r: No such file or 
directory" when I try to run a Ruby script, one with the shebang you 
told me of earlier.
Posted by Jon Cairns (jonathan_c)
on 2013-02-06 17:42
(Received via mailing list)
>
> OK. Did that. And, yes, now I see that Ruby directory in my path, first
>  thing in fact. But, I'm still getting "env: ruby\r: No such file or
> directory" when I try to run a Ruby script, one with the shebang you
> told me of earlier.


I think Hassan's right, that \r looks out of place. That's a carriage
return character, which shouldn't be there. Just try running this from 
the
command line:

    $ /usr/bin/env ruby -v

If you get the ruby version printed out then the problem isn't your path 
or
RVM set up, it's a character issue in the file that you're trying to 
run.
All decent text editors/IDEs have an option to show special characters. 
Try
deleting the entire "#!/usr/bin/env ruby" line and retyping it by hand,
then running again.
Posted by Peter Bailey (peterbailey)
on 2013-02-06 17:51
Jon Cairns wrote in post #1095566:
>>
>> OK. Did that. And, yes, now I see that Ruby directory in my path, first
>>  thing in fact. But, I'm still getting "env: ruby\r: No such file or
>> directory" when I try to run a Ruby script, one with the shebang you
>> told me of earlier.
>
>
> I think Hassan's right, that \r looks out of place. That's a carriage
> return character, which shouldn't be there. Just try running this from
> the
> command line:
>
>     $ /usr/bin/env ruby -v
>
> If you get the ruby version printed out then the problem isn't your path
> or
> RVM set up, it's a character issue in the file that you're trying to
> run.
> All decent text editors/IDEs have an option to show special characters.
> Try
> deleting the entire "#!/usr/bin/env ruby" line and retyping it by hand,
> then running again.

OK. I get:
ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-darwin12.2.0]

I'm using RubyMine as my Ruby editor. I've never had a problem with it. 
But, I did delete the shebang and re-enter it. Still no luck.
Posted by Peter Bailey (peterbailey)
on 2013-02-06 17:56
Hassan Schroeder wrote in post #1095557:
> On Wed, Feb 6, 2013 at 7:48 AM, Peter Bailey <lists@ruby-forum.com>
> wrote:
>
>> I just put "#!/usr/bin/env ruby"  into one of my Ruby scripts now. I
>> tried to run it and it says:
>>
>> env: ruby\r: No such file or directory
>
> ? Did you copy/paste that from somewhere? That \r looks out of
> place.
>
> 08:11 ~ $ cat bar
> #!/usr/bin/env foo
>
> WAT
> 08:11 ~ $ ./bar
> env: foo: No such file or directory
> 08:11 ~ $

Yes, I see that "\r" whenever I try to run a Ruby script. I have no idea 
where it's coming from. I thought it might be because the Ruby script 
I'm trying to run originally came from a PC. But, my RubyMine software 
is a Mac app., so, it should be saving the file as a Mac file, not a 
Windows file.
Posted by Peter Bailey (peterbailey)
on 2013-02-06 18:00
Peter Bailey wrote in post #1095573:
> Hassan Schroeder wrote in post #1095557:
>> On Wed, Feb 6, 2013 at 7:48 AM, Peter Bailey <lists@ruby-forum.com>
>> wrote:
>>
>>> I just put "#!/usr/bin/env ruby"  into one of my Ruby scripts now. I
>>> tried to run it and it says:
>>>
>>> env: ruby\r: No such file or directory
>>
>> ? Did you copy/paste that from somewhere? That \r looks out of
>> place.
>>
>> 08:11 ~ $ cat bar
>> #!/usr/bin/env foo
>>
>> WAT
>> 08:11 ~ $ ./bar
>> env: foo: No such file or directory
>> 08:11 ~ $
>
> Yes, I see that "\r" whenever I try to run a Ruby script. I have no idea
> where it's coming from. I thought it might be because the Ruby script
> I'm trying to run originally came from a PC. But, my RubyMine software
> is a Mac app., so, it should be saving the file as a Mac file, not a
> Windows file.


I got it! Yes, it was indeed some Windows gibberish. I opened my Ruby 
script in BBEdit and saved it as a Unix file. Now, the script works!

Thank you all for your help!
Posted by Jon Cairns (jonathan_c)
on 2013-02-06 18:06
(Received via mailing list)
> Yes, I see that "\r" whenever I try to run a Ruby script. I have no idea
> where it's coming from. I thought it might be because the Ruby script
> I'm trying to run originally came from a PC. But, my RubyMine software
> is a Mac app., so, it should be saving the file as a Mac file, not a
> Windows file.

We can see whether it's something in the file if you pass the binary 
file
(with the shebang) through xxd, and paste the output:

    $ xxd /path/to/your/executable

That will give us the hex codes of the characters in your file, and we 
can
see whether there's something dodgy in there.

Cheers
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.