How to execute a Ruby script in Terminal?

前端 未结 9 1629
南笙
南笙 2020-12-04 06:15

I\'ve set everything up that I need on my Mac (Ruby, Rails, Homebrew, Git, etc), and I\'ve even written a small program. Now, how do I execute it in Terminal? I wrote the pr

9条回答
  •  囚心锁ツ
    2020-12-04 07:17

    Open Terminal

    cd to/the/program/location
    ruby program.rb
    

    or add #!/usr/bin/env ruby in the first of your program (script tell that this is executed using Ruby Interpreter)

    Open Terminal

    cd to/the/program/location
    chmod 777 program.rb
    ./program.rb
    

提交回复
热议问题