1

Hi,

I've created a small program in C++ I would like to run like a command from the terminal. With that I mean that I can open the program from and in the terminal (as it is a console application) regardless of which directory I'm in, without having to specify the path to the program. I know how to arrange it so that I would only have to type /program_name, but I'm interested in how the above would work. Thanks in advance!

muru
  • 193,181
  • 53
  • 473
  • 722
Simeon
  • 13
  • 3
  • 3
    Put the compiled executable in a directory that's on your `PATH`: see [How to run a program without typing the full path?](http://askubuntu.com/questions/104662/how-to-run-a-program-without-typing-the-full-path?) – steeldriver Jan 27 '16 at 22:22
  • @steeldriver Thanks, I didn't find that thread on my searches, sorry – Simeon Jan 27 '16 at 22:30
  • If the program is just for you, put it in `~/bin/program_name`. Then you can run it from anywhere via `program_name`. – Doug Smythies Jan 27 '16 at 22:52

1 Answers1

0

You can either copy your executable to some folder in your $PATH (if you compiled your app statically) to see what is in your $PATH type:

echo $PATH

/usr/local/bin is probably the best choice. So copy it there by:

sudo cp yourexe /usr/local/bin

Or you can add additional directory to your PATH. You can do this by putting:

PATH=$PATH:/path/to/some/folder

in your ~/.profile file. Read more about it here. You will probably need to logout after doing this.

Dimitri Podborski
  • 2,505
  • 16
  • 22