#!/usr/bin/env ruby not working?

2,020 views
Skip to first unread message

Chad Woolley

unread,
Nov 7, 2009, 1:54:37 PM11/7/09
to RVM
Hi,

This may be off-topic or unrelated to RVM, but it just cropped up
after I installed RVM so maybe you can help.

When I try to directly run ruby scripts with the following shebang:

#!/usr/bin/env ruby

I get this error:

env: ruby\r: No such file or directory

Now, ruby is on my path:

$ which ruby
/usr/bin/ruby
$ ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
$ ls -al /usr/bin/ruby
lrwxr-xr-x 1 root wheel 76 Aug 7 2008 /usr/bin/ruby ->
../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby

AND this works outside of a script shebang:

$ /usr/bin/env ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]

What's up? I don't understand enough about 'env' to debug this
problem - I thought it just looked on the path, but that doesn't seem
to be the case...

Thanks,
-- Chad

Steven Parkes

unread,
Nov 7, 2009, 1:58:10 PM11/7/09
to rubyversi...@googlegroups.com
> env: ruby\r: No such file or directory

Sounds like you're trying to run a script that has DOS/Windows line
endings (\r\n) on a machine that doesn't (linux/unix/mac os)?

Wayne Seguin

unread,
Nov 7, 2009, 1:59:17 PM11/7/09
to rubyversi...@googlegroups.com, Wayne Seguin
On Nov 07, 2009, at 13:54 , Chad Woolley wrote:
>
> Hi,
>
> This may be off-topic or unrelated to RVM, but it just cropped up
> after I installed RVM so maybe you can help.
>
> When I try to directly run ruby scripts with the following shebang:
>
> #!/usr/bin/env ruby
>
> I get this error:
>
> env: ruby\r: No such file or directory

^ This looks very suspicious, that is a 'carriage return' character.
Perhaps check the line endings to ensure that they are unix style with
nothing extra?

I verified that if I add a dos style ^M to the end of the shebang I
indeed get:

env: ruby\r: No such file or directory

When I remove it and ensure unix line break it works fine.

~Wayne

Wayne Seguin

unread,
Nov 7, 2009, 1:59:42 PM11/7/09
to rubyversi...@googlegroups.com, Wayne Seguin

I believe that Steven is correct here ;)

~Wayne

Reply all
Reply to author
Forward
0 new messages