Rails 5.2.3 windows 10 error: ‘ruby\r’: No such file or directory

Hi, need a little help deploying a Ruby on Rails App here.
Getting this error after running “flyctl deploy”

=> CACHED [stage-3 4/7] COPY --from=gems /usr/local/bundle /usr/local/bundle                                 0.0s
 => CACHED [stage-3 5/7] COPY . .                                                                             0.0s 
 => CACHED [stage-3 6/7] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe/ruby/' /app/bin/* &&     sed -i '  0.0s 
 => ERROR [stage-3 7/7] RUN bin/rails fly:build                                                               0.3s 
------
 > [stage-3 7/7] RUN bin/rails fly:build:
#20 0.315 /usr/bin/env: ‘ruby\r’: No such file or directory
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/bash -o pipefail -c ${BUILD_COMMAND}]: exit code: 127

Try changing that to:

sed -i 's/ruby.exe\r*/ruby/'

If that works for you, I’ll fix flyctl launch for future users.

Hi, thanks for your help. Unfortunately getting the same error.

 => CACHED [stage-3 4/7] COPY --from=gems /usr/local/bundle /usr/local/bundle                      0.0s 
 => [stage-3 5/7] COPY . .                                                                         0.3s 
 => [stage-3 6/7] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe\r*/ruby/' /app/bin/* &&     s  0.3s 
 => ERROR [stage-3 7/7] RUN bin/rails fly:build                                                    0.4s 
------
 > [stage-3 7/7] RUN bin/rails fly:build:
#20 0.346 /usr/bin/env: ‘ruby\r’: No such file or directory

While I am using Windows 11, I can deploy a Rails app from there. Can you try the following command so we can see the contents of your bin\rails file?

ruby -e "p File.open('bin/rails', 'rb') {|file| file.read}"

Here’s what I get:

PS C:\Users\rubys\welcome> ruby -e "p File.open('bin/rails', 'rb') {|file| file.read}"
"#!/usr/bin/env ruby.exe\nAPP_PATH = File.expand_path(\"../config/application\", __dir__)\nrequire_relative \"../config/boot\"\nrequire \"rails/commands\"\n"

I’m having the same error on Windows 11:
/usr/bin/env: ‘ruby\r’: No such file or directory

@paulosiqueira can you run the following command and tell me what you see?

ruby -e "p File.open('bin/rails', 'rb') {|file| file.read}"

Try change

sed -i 's/ruby.exe/ruby/' /app/bin/* && \

or (if you have latest dockerfile, which has updated recently)

sed -i 's/ruby.exe\r*/ruby/' /app/bin/* && \

to

sed -i 's/ruby\r/ruby/' /app/bin/* && \

inside your docker file

@rubys
I also encountered this error

‘ruby\r’: No such file or directory

I used this command and uploaded successfully

sed -i 's/ruby.exe\r*/ruby/'

Thank you!

I was facing the same problem on Windows 10.

As a fix, I opened the file in Notepad++, and in the find & replace tab, I put \r in the find tab and kept the replace tab empty.

If you’re implementing the same solution, make sure you check the extended box in the Search mode tab of the find & replace function.

Cheers!

1 Like

I also faced the same problem yesterday and I remember that for most applications, the bin folder serves as the starting point.

So, in this case, the bin/rails file is a script that serves as an entry point to run various Rails commands, such as starting the Rails server, generating database migrations, or running tests.
When you encountered the error /usr/bin/env: ‘ruby\r’: No such file or directory, the Linux environment didn’t recognize the Windows-style line ending in the bin/rails script.

To fix this issue, you can convert the line endings of the bin/rails file to Linux-style line endings (LF). If you’re using a Windows text editor, check its settings for an option to change line endings to Unix/Linux-style (LF). Alternatively, you can use a tool like dos2unix to convert the file. Once you’ve converted the line endings, you should be able to deploy your app on fly.io without encountering the error.

I used Notepad++ all I did is opened the bin/rails file with np++ and went into the Edit option I selected EOL conversion and chose the UNIX(LF).

I hope this might help you.

2 Likes