Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 1.9 If I have a shebang pointing to ruby, why doesn't the system see it?

Tags:

ruby

I'm using Ubuntu. I'm trying to run a ruby file todo.rb I added this shebang as the very first line of the file

#!/usr/bin/env ruby

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:

MY_RUBY_HOME=/home/tallercreativo/.rvm/rubies/ruby-1.9.2-p290
PATH=/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290/bin:/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/tallercreativo/.rvm/rubies/ruby-1.9.2-p290/bin:/home/tallercreativo/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
GEM_PATH=/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290:/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290@global
RUBY_VERSION=ruby-1.9.2-p290

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?

like image 316
leonel Avatar asked Dec 04 '22 04:12

leonel


2 Answers

You need to first make your script executable:

chmod +x todo.rb

then you need to run it like so:

./todo.rb

You cannot run it by just saying todo.rb, unless you place it in your PATH, in which case you can do so from anywhere.

like image 177
Andrew Marshall Avatar answered Mar 17 '23 11:03

Andrew Marshall


You're missing the ruby at the end of your env command. Did you mean:

#!/usr/bin/env ruby

You need to tell env what executable you're looking for.

(Question Updated)

Are you executing your code like this? todo.rb ? You either need to provide the full path to your script (/home/you/project/todo.rb) or a relative path (./todo.rb) unless that directory is inside your $PATH.

like image 20
John Ledbetter Avatar answered Mar 17 '23 12:03

John Ledbetter