Let's suppose I have compiled something and I run it like so:
$ /path/to/my/executable/mycmd Hello World
What do I need to do to run it like
$ mycmd Hello World
from everywhere in my computer?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
What you are looking for is the
PATH environmental variable. It tells the shell, where it needs to look for programs. You can see the current value of that variable using
Now... The best practice if you want use some new program is to install it using the package management program for your distribution. But in this case, I assume you are dealing with a program that is not delivered by any available software package. For such programs, you have two options:
/opt/bin/- those should already be in your
PATH. (Look inside these folders and if there are many files in them, then it is the wrong place to put your own program and you have to look at other folders listed in your
PATH variable. This is less secure, because it defines additional folders where programs can be kept and someone might play a trick on you, putting his own program there for you to run.
You can modify the
PATH variable either temporarily, using
=), or permanently by adding the above line to your
.bashrc file (assuming you use