How to add an executable program to PATH environment variable?
Make these steps to add a C program to PATH variable.
- First of all make a back up from important PATH Variable with
echo $PATH > ~/path.txt
- Compile the C source code with
gcc Numbers.c -o Numbers
- Suppose the executable output file
Numbers is place under ~/barname.
- Run
export PATH="$PATH:~/barname" to append ~/barname folder to PATH variable.
- Now you can run the executable file i.e:
Numbers from any location on Terminal.
I answer to similar question at Iranian Ubuntu community.
and now translate it to English.
Edit
By performing jonathan-leffler notes in comment section, i can change above answer to:
Having many different directories inside PATH environment variable not recommend and have performance issue.
If i want to use specific programs only for myself, create a new directory in current user (me) home folder. mkdir $HOME/bin Then copy Numbers program and all of other programs in to it. for example cp ~/barname/Numbers ~/bin. And finally add only one directory i.e: $HOME/bin to PATH variable by export PATH="$PATH:$HOME/bin".
In a situation when working on a real multi user system, like when work as Sysadmin its better to copy programs to /usr/local/bin and then adding this to PATH by export PATH="$PATH:/usr/local/bin. Now every users can access and run programs.