0

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.

2
  • Make it executable and put it somewhere in your $PATH (the usual place is /usr/local/bin). Commented Oct 4, 2018 at 0:04
  • The default .bashrc on some linux distros also adds $HOME/bin to the path if it exists. I normally symlink things into it. Commented Oct 4, 2018 at 1:42

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I have a dir like this for little scripts and things I have written over time. These are mostly ruby and with the #! and executable you can also omit the .rb
Personal preference, I like to keep the file extensions :-)
@AndrewSchwartz When I run ln -s ~/bin/myProgram.rb /path/to/myProgram.rb, it gives me an error ln: ~/bin/myProgram.rb: File exists, but when I go into ~/bin, there isn't anything named myProgram.rb
@Mining15 I got it backwards, it's ln -s existing_file new_link_file. Updated my response to reflect this.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.