Mining15
Mining15

Reputation: 83

How can I run a ruby program as its own command?

It is possible to put the #!/usr/bin/env ruby at the top and run chmod +x myProgram.rb to run it from the terminal by doing something like ./myProgram.rb.

This requires the path to the .rb file. I am trying to run the program by just typing myProgram into a terminal.

Upvotes: 0

Views: 132

Answers (2)

Andrew Schwartz
Andrew Schwartz

Reputation: 4657

Adding an alternative that I tend to prefer. Instead of balooning my PATH variable, I put a single folder such as ~/bin in my PATH. Then I create symlinks from here to any executables I have in odd locations. E.g. ln -s /path/to/myProgram.rb ~/bin/myProgram.rb

Upvotes: 1

Jamie Clinton
Jamie Clinton

Reputation: 286

You need to add the directory to the PATH variable. When you type a command in *nix, it tries to look up the command in all the directories in PATH.

Here is a random article explaning how https://opensource.com/article/17/6/set-path-linux.

Upvotes: 0

Related Questions