How to make Ruby file run as executable?

15,871

I assume you're using Linux or OS X and creating the file on a disk accessible from Windows? Windows does not use shebangs, and it does not use Unix file modes. You will need to associate files with the .rb extension to the Ruby executable; details for that operation can be found at this Stack Overflow question; once you have done this, you can run C:\whatever\test.rb or C:\whatever\test to execute the script.

Share:
15,871
Apoorv Saxena
Author by

Apoorv Saxena

Updated on June 18, 2022

Comments

  • Apoorv Saxena
    Apoorv Saxena almost 2 years

    I want my Ruby Script File to run as executable from any directory of Windows XP. I have created a test.rb (Ruby Script file) and want to run it from any directory of my Windows as "test" for example, "C:\test" or "C:\Directory\test" runs my file test.rb.

    #!/usr/bin/envy ruby
    
    p "Hi this is my test file"
    

    I have added the shebang code in my ruby file but when I have to run the Ruby Script, I have to locate my Script file and run it expicitly as "ruby test.rb".

    I have also made the file executable by executing the command:$ chmod +x hello-world.rb , but it still does not work.

    Thanks in advance.

  • Iain S
    Iain S about 11 years
    This doesn't help if you want to send your new program to someone else, who doesn't have Ruby installed..