Assuming the helloworld
executable is in newDir
directory in the home
folder.
Then the absolute path for
helloworld
is
/home/user_name/newDir/helloworld
Now add the below line your ~/.bashrc
file.
export PATH=$PATH:/home/user_name/newDir/
Now open any new terminal (any directory), you will be able to run the command helloworld
Adding the path of the executable in the PATH
environment variable will allow the user to run the executable available in the mentioned directory any where in the system. Check the value of your $PATH
with echo $PATH
. It probably contains the system directories /usr/bin
and /bin
where most system executables sit. But don't mess these directories by adding your own programs there (leave them to be handled by your package manager).
You might want to avoid having a too long PATH
environment variable; then, assuming you do have a $HOME/bin/
directory mentioned in that $PATH
, you could just add a symbolic link there, e.g.
ln -sv /home/user_name/newDir/helloworld $HOME/bin/helloworld