3 Answers
3

For example let me assume, you have an executable myscript. You need to run it from a terminal as,

/path/to/myscript

User level Change

If you add the PATH of that executable to ~/.bashrc, you can run the executable with name only from anywhere (Avinash Raj already mentioned), as

myscript

But the change will be affected in user level. That means if you have any other user(s) they could not access the executable with name only. If they have proper permission they need to run the executable as,

/path/to/myscript

Also, you will not be able to run the script as sudo as it is not in PATH of root, To run as sudo you need to use,

sudo /path/to/myscript

system level change

If you put your script in /usr/local/bin it can be accessed system wide and for all users. In that case any user can run your executable as (subject to having proper permissions)

Adding the location of the file to your $PATH variable in your ~/.bashrc file will only allow you to execute from any location, whereas putting it in /usr/bin/ will allow all users on your system to execute that file from any location.

Why is that? Because, your ~/.bashrc file is only visible to you as a user. So all variable changes done are limited to you. Whereas, adding that file to /usr/bin will allow the file to remain there for all users and since /usr/bin is present in the $PATH variable unless someone removes it, will allow all users to execute it from any location.