Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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 echo:

echo "$PATH"

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:

  1. Install the program system-wide, in a place where your system does not put any files installed from packages. On most systems, such "safe" folders include /usr/local/bin/ and /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.)
  2. Modify 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

    export PATH="$PATH:/path/to/your/executable"
    

    (mind the $PATH after =), or permanently by adding the above line to your .bashrc file (assuming you use bash).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.