This question already has an answer here:

How is install different from a simple copy, cp or dd? I just compiled a little utility and want to add it to /usr/sbin so it becomes available via my PATH variable. Why use one vs the other?

marked as duplicate by Jeff Schaller, Stephen Rauch, G-Man, peterh, Romeo Ninov Nov 2 '17 at 6:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 15 down vote accepted

To "install" a binary compiled from source the best-practice would be to put it under the directory:

/usr/local/bin

On some systems that path is already in your PATH variable, if not you can add it by adapting the PATH variable in one of your profile configuration files ~/.bashrc ~/.profile

PATH=${PATH}:/usr/local/bin

dd is a low level copy tool that is mostly used to copy exactly sized blocks of the source which could be for example a file or a device.

cp is the common command to copy files and directories also recursively with the option -r and by preserving the permissions with the option -p.

install is mostly similar to cp but provides additionally the option to set the destination file properties directly without having to use chmod separately.

cp your files to /usr/local/bin and adapt the PATH variable if needed. That's what I would do.

  • 2
    If you're interested in why you should put it under /usr/local/ there is a pretty good answer here: unix.stackexchange.com/questions/8656/… – cakuzo Jul 27 '15 at 18:25
  • In fact if you look at man 1 install you will find that there are a good many options that can be used when installing a file. For example, you can check if the file already exists, if so you can check if they are duplicate files and abort the install if the file is already installed. Configure mode, ownership and many other features all with a single command. – OldTimer Aug 5 '15 at 23:06

Install copies files with the default mode 755.

Install can be configured to set the owner or group of a file and/or the mode of a file.

Install can be configured to backup the original file before it is replaced.

  • Assuming you're using the GNU versions, cp supports backups as well. – Nate Eldredge Jul 28 '15 at 4:37

The primary difference between install and cp is that if the destination file already exists install unlinks it first.

This difference is not pointed out in the manual pages. The things listed in the other answers also matter -- both programs have different options, and also GNU install has different options than BSD install so portable Makefiles are limited to a common subset.

Why unlinking (which can be also done by rm before cp) matters? If you have a file with two hardlinks and modify it using one of the hardlinks, it's modified also in the other place on the filesystem. But if you remove one of the hardlinks first and replace it with modified file, the other place keeps the original version.

More probable scenario is that you update a program or a library while it is in use. If the binary is unlinked first, it won't affect the running program. Here is a nice post with more details: http://en.chys.info/2009/05/install-vs-cp-and-mmap/

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