small medium large xlarge

20 Apr 2012, 16:24
Leonel Santos (11 posts)

I added this shebang as the very first line of the file #!/usr/bin/env

I go to the directory where the rb file is located and then run todo.rb and get error “todo.rb: command not found”.

So I went directly to the /usr/bin directory. I found the env command and ran it. The output of the env command displays ruby paths and ruby data, like this…





So since, I couldn’t make it work, I changed the shebang to point to ruby directly: #!/home/tallercreativo/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

and I get same command not found error.

What’s wrong?

20 Apr 2012, 18:10
David Copeland (501 posts)

There’s two things at play.

1 - /usr/bin/env requires an argument to work, so your shebang line should read:

#!/usr/bin/env ruby

That tells @env@ to run the command @ruby@ from wherever it is in your environment path.

2 - your app must be in your path, so to run todo.rb from the current directory, you’d need to do


(Note the @./@). Not sure how far along you are in the book, but if you have setup a project with the executable in the @bin@ directory, then you’d need to do


Essentially, since your @PATH@ doesn’t contain the current directory or your project’s @bin@ directory, you need to explicitly include the path to the executable.

If all that sounds awful, it’s not a big deal when users install apps with RubyGems, since the executable gets installed into a location that is likely in the user’s path.

28 Oct 2012, 11:48
Weihong Guan (1 post)

I just began reading this book. It is quite inspiring. I believe it would be better if adding

chmod +x todo.rb

before excute it. For bash guys, this is quick basic, while for fleshmen, it is quite an issue.