install is a versatile file-copying command in Linux and macOS. It’s perfect for the power-user looking for efficiency. Read this article to discover how to work smarter—not harder.
Wait—It’s Not For Installing Software?
install command might have the most misleading name of any of the Linux commands. It doesn’t actually install any software. If you’re trying to install a software package from the command line in Ubuntu or another Debian-based distribution use the
apt-get command. On other Linux distributions, use your Linux distribution’s package management tool instead—for example,
dnf on Fedora or
zypper on openSUSE.
So What Does install Do?
In a nutshell
install combines elements from the
chown (change owner),
chmod (change mode),
mkdir (make directory), and
strip (strip symbols) commands. It lets you use functions from all of those in one single action.
install command can:
- Copy files like the
- Choose whether to overwrite existing files.
- Create the target directory if it does not exist, like
- Set the user permission flags of the files, just like the
- Set the owner of the files, just like the
- Remove non-essential baggage from executable files, just like the
Despite all that functionality, the
install command doesn’t have too many options to contend with.
When Would You Use It
install command probably won’t be used every day. It’s useful, but only for certain situations. One scenario where
install comes into its own is software development. Let’s say you’re programming a new utility. You’ll need to do testing outside of the development environment. To do that you need to copy the new program files to a test directory. The test directory might need to be created, and you need to set the correct permissions and ownership for the files.
Because development is an iterative activity, you can end up doing this sequence of actions many, many times. The
install command does all the heavy lifting for you. Finally, when your new utility is ready to be deployed, you can use
install to copy it with the correct permissions to its final working location.
A programmer is working on just such a new utility, called
ana. It consists of an executable binary file and a database. After testing, it must be copied to
/usr/local/bin to make it available for all users of the Linux system. You’ll need to substitute the filenames and directory paths in our example for the files and paths you’re using on your computer when you use
Until it is ready for release it will be tested in a directory called
~/test/ana. Members of the
geek group will have read and execute permissions. Other users will have read and execute permissions also. The
install command uses the same numeric representation for permissions as
chmod does. Our programmer has decided that the permissions must be set to:
- Owner: Read, write, and execute.
- Group: Read and execute.
- Others: Execute only.
How to Use the
Our fictional programmer’s working directory is
~/work. He has written the program, compiled it, and produced a binary called
ana. He already created the database file that
ana works with,
Words.db. So both files are ready for testing. Let’s take a look at them:
ls -l ana Words.db
ana utility he has just written creates anagrams out of a phrase provided on the command line. Verification testing is quite straightforward.
Our programmer has invoked
ana with the phrase “biscuit” and all seems well. He now wants to copy these two files to the
~/test/ana directory to see if the new utility functions correctly away from the development environment. He issues the following command:
install -D -v ana Words.db -t ~/test/ana
The options used on the command line were:
- D: Create directories, including parent directories, if required.
- v: Verbose, list each directory as it is made and each file copy as it is performed.
- t: Target directory.
We can see that
install creates the
~/test directory, and then creates the
~/test/ana directory. The files are listed one by one as they are copied to the target directory.
Listing the files in
~/test/ana confirms they have been copied over correctly.
The next step is to test the
ana utility by invoking it in the
The utility operates as expected, which is great. However, the permissions are not correct. The requirement is to set members of the group
geek to have read and execute permissions, and for other users to have execute only.
We can address both of those issues quite simply with the following command. Note the use of
sudo to run the command with root permissions. The
-g and options require this. We’ll be asked for our password when we issue the command.
sudo install -b -S .bak -o dave -g geek -m 751 ana Words.db -t ~/test/ana
-b(backup) option creates backups of the files before they are overwritten.
-S(suffix) option defines the suffix for the backup files. If you do not provide a suffix a
~(tilde) is used. We’re asking
installto use a suffix of
- We set the owner of the file to be
-g(group) option requires the name of a group. This becomes the owner group of the files. The group we are going to use is called
-m(mode) option sets the file modes for the files, using the standard
We no longer need to use the
-D (create directories) option, because we know the test directory already exists. We’ve also omitted the
-v (verbose) option. Listing the files in our
~/test/ana directory shows us the file details:
This confirms that all our requirements have been met.
- The files have been copied across to the testing directory.
- The permissions have been set correctly.
daveis the owner of the files.
geekgroup is the owner group of the two files.
- Backup copies have been made of each file, called ana.bak and Words.db.bak.
All that was achieved through the use of one command. Neat.
Our programmer makes some final changes to the utility and re-compiles. The files that have changed need to be copied over to the
~/test/ana directory from the
~/work directory. We can do this by using the
-C (compare) option. If the source file and target file are the same, the source file is not copied.
sudo install -C -b -S .bak -o dave -g geek -m 751 ana Words.db -t ~/test/ana
Listing the files in the target directory shows us that the file size of the
ana file has changed. It is bigger than the
ana.bakfile. The timestamp on
ana has also changed. These changes are because the new version of the file has been copied here.
The file size and timestamp of the
Words.db file have not changed. No changes were made to the
Words.db file, so it was not copied over. On a project with many files the
-C (compare) option can save a lot of time and hard drive churn, by only copying those files that have been changed.
The programmer has again tested that the
ana utility continues to operate.
It is time to use
install to copy the files to the
/usr/local/bin directory. This will make the new utility available for all users of this Linux computer. We know that
/usr/local/bin exists, so we don’t need to create that directory. We can use a modified version of our last command.
We’ve changed the target directory to be
/usr/local/bin. We’ve removed the
-C (compare) option because there are no copies of these files in the target directory yet, so there is nothing to compare against. Likewise, there is nothing to back up, so we can remove the
-b (backup) option and the
-S (suffix) option.
sudo install -o dave -g geek -m 751 ana Words.db -t /usr/local/bin
We can list that the files have arrived in
And as a final test let’s change directory to our home directory and see if we can invoke our new utility from there.
Note that we didn’t need to preface the
ana command with
./ which means it is running from
/usr/local/bin. Mission accomplished.
We mentioned that install can strip out redundant symbol tables and other baggage from within the binary file, to reduce it in size. Let’s do that now. Note that the command below does not include Words.db. This is because Words.db is a database file, not a binary executable. To copy and shrink the binary file
ana we can use the following command. We have added the -s (shrink) option with a lower case “s.” We’ve added back in the -b (backup) option and the -S (suffix) option, with an uppercase “S.”
sudo install -s -b -S .bak -o dave -g geek -m 751 ana -t /usr/local/bin
Listing the files in
/usr/local/bin allows us to compare the size of the
ana file with its backup version. The
ana file has been reduced to almost 60% of its previous size.
ls -l /usr/local/bin
install command caters to a pretty niche use. For many people it won’t be used day in and day out, or possibly from month to month. Despite that, the
install command is a good tool to be familiar with and to have in your arsenal of tricks. For those occasions when you need it, it rewards your learning curve with boosts in efficiency, simplicity and simply fewer keystrokes.
- › How to Fix the Linux Boots Into the BIOS Error
- › How to Copy Files and Directories in the Linux Terminal
- › How to Check Your RAM Speed
- › Is a VPN Worth Paying For?
- › 1080p vs. 1440p vs. 4K Monitors: How Big Is the Difference?
- › 5 Google Maps Scams (And How to Avoid Them)
- › Acer’s New Swift Edge 16 Laptop Is Thin and Has Wi-Fi 7
- › Worried About Handheld Gaming PC Battery Life? Just Buy a Powerbank