Passionate Engineer
Passionate Engineer

Reputation: 10412

Ruby executable not working

On Ubuntu,

I've created an executable file for Ruby with

bin/hello (name of the file)

#!/usr/bin/env ruby

But whenever I run bin/hello from bin's parent directory

It comes up with : No such file or directory

I'm sure there isn't any typo or anything.

What could be wrong?

Upvotes: 0

Views: 163

Answers (2)

Shubham SHARMA
Shubham SHARMA

Reputation: 19

You have to make the file executable

chmod +x bin/hello

After that run it by writing

./bin/hello

Upvotes: 0

nneonneo
nneonneo

Reputation: 179422

I think it's most likely you saved the file with Windows newlines (CRLF); the invisible CR before the end of the first line causes the executable search to fail, and part of the error message "erases" itself due to the carriage return.

Look at the file in vim and see if ^M shows up at the end of lines. Alternately, you can look at the output of xxd bin/hello | head -n 10 and see if 0D 0A (CR LF) appears. If you suspect CRLF, you can use dos2unix to fix the file back to Unix (LF) newlines.

Upvotes: 1

Related Questions