Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an executable. I want to execute the executable in terminal with name only like other commands.

I can put my executable in /usr/local/bin or I could add its PATH to ~/.bashrc. Both will work.

What is better? Is there any difference?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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


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


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,


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)


In that case you can run the executable as sudo also as,

sudo myscript

Now choose one way depending upon your need.

share|improve this answer

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.

share|improve this answer

If you put the executable file in /usr/bin or /usr/local/bin, then you will be able to run that program by only specifying the name (your-program instead of /usr/local/bin/your-program).

If you instead add the directory containing the program to the ~/.bashrc file to the PATH, then any executable file present in that directory can be launched by only typing its name.

share|improve this answer
This information is false, you can stil launch the executable even if you are not in "that directory". –  Lekensteyn Mar 29 '14 at 14:27
How is this false?, please explain a bit more. –  Avinash Raj Mar 29 '14 at 14:42
Ok, I had a hard time reading your answer (and thereby made an error) so I edited it to remove the confusion and remoted the downvote. Hopefully it helps. –  Lekensteyn Mar 29 '14 at 16:21
So, the question is: What is better? Is there any difference? You practically didn't say nothing more than the OP. –  Radu Rădeanu Mar 30 '14 at 7:11
I answered for the OS's question but not in a brief format. –  Avinash Raj Mar 30 '14 at 7:46

Your Answer


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.