Ruby 1.9.3-p362 on Mac OSX

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

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.

Jon C. 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

Jon C. wrote in post #1095551:

On 6 February 2013 15:48, Peter B. [email protected] 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:

On 6 February 2013 15:48, Peter B. [email protected] 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

On Wed, Feb 6, 2013 at 7:48 AM, Peter B. [email protected]
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 ~ $

Jon C. 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.

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.

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.

Jon C. 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.

Hassan S. wrote in post #1095557:

On Wed, Feb 6, 2013 at 7:48 AM, Peter B. [email protected]
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.

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

Peter B. wrote in post #1095573:

Hassan S. wrote in post #1095557:

On Wed, Feb 6, 2013 at 7:48 AM, Peter B. [email protected]
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!