Ubuntu – How to open a Ruby file in terminal

command linefilesruby

I have a ruby file saved on my desktop as test.rb.
How can I open it with terminal?
I have already tried to use /home/desktop/test.rb and what I get in response is bash: /home/desktop/test.rb: No such file or directory.

Best Answer

You can use the ruby command, which calls the Ruby interpreter on your file:

ruby ~/Desktop/test.rb

This way you don't need to make your file executable.

(The tilde symbol ~ is a shorthand for the path to your home folder which is /home/<your-username>.)

If you still need to make your script executable I hope you remembered to type the shebang line on the first line of your script:

#!/usr/bin/ruby

then run chmod +x ~/Desktop/test.rb on the terminal to make test.rb executable.