When you run make, you're instructing it to essentially follow a set of build steps for a particular target. When make is called with no parameters, it runs the first target, which usually simply compiles the project. make install maps to the install target, which usually does nothing more than copy binaries into their destinations.
Frequently, the install target depends upon the compilation target, so you can get the same results by just running make install. However, I can see at least one good reason to do them in separate steps: privilege separation.
Ordinarily, when you install your software, it goes into locations for which ordinary users do not have write access (like /usr/bin and /usr/local/bin). Often, then, you end up actually having to run make and then sudo make install, as the install step requires a privilege escalation. This is a "Good Thingโข", because it allows your software to be compiled as a normal user (which actually makes a difference for some projects), limiting the scope of potential damage for a badly-behaving build procedure, and only obtains root privileges for the install step.
When you run make, you're instructing it to essentially follow a set of build steps for a particular target. When make is called with no parameters, it runs the first target, which usually simply compiles the project. make install maps to the install target, which usually does nothing more than copy binaries into their destinations.
Frequently, the install target depends upon the compilation target, so you can get the same results by just running make install. However, I can see at least one good reason to do them in separate steps: privilege separation.
Ordinarily, when you install your software, it goes into locations for which ordinary users do not have write access (like /usr/bin and /usr/local/bin). Often, then, you end up actually having to run make and then sudo make install, as the install step requires a privilege escalation. This is a "Good Thingโข", because it allows your software to be compiled as a normal user (which actually makes a difference for some projects), limiting the scope of potential damage for a badly-behaving build procedure, and only obtains root privileges for the install step.
A lot of software these days will do the right thing with only make install.
In those that won't, the install target doesn't have a dependency on the compiled binaries.
So to play safe, most people use make && make install or a variation thereof just to be safe.
software installation - Difference between "make install" and "sudo make install" - Unix & Linux Stack Exchange
software installation - What ./configure make and make install does - Unix & Linux Stack Exchange
unix - Why always ./configure; make; make install; as 3 separate steps? - Stack Overflow
Difference between configure/make/make install.
Videos
Make is a general purpose workflow program, usually used for compilation. But it can be used for anything.
When you do something like "make all", the make program executes a rule named "all" from a file in current directory named "Makefile". This rule usually calls the compiler to compile some source code into binaries.
When you do "make install", the make program takes the binaries from the previous step and copies them into some appropriate locations so that they can be accessed. Unlike on Windows, installation just requires copying some libraries and executables and there is no registry requirement as such. In short, "make install" just copies compiled files into appropriate locations.
make install does whatever the Makefile author wants it to do. Typically, by this point, it is too late to change the install directory, as it is often known earlier, during the build, so help files and configuration files can be referenced with the correct pathnames.
Many projects use the GNU Autotools to try to improve their portability among hardware and operating system differences. (Different Unix variants use slightly different headers for declarations of functions that are slightly off the usual path -- except most programs need one or another of the ones declared in different locations.)
When a project does use the Autotools, the normal mantra to install it is:
./configure
make
make install
The ./configure typically allows you to use a command line option like --prefix /opt/apache or something similar to specify a different pathname. /usr/local/ is a common default prefix. It is far easier for locally built software to live in one place and distribution-provided software to live in the "main directories": /usr/ /bin/, and so on. (Packagers are very careful to never touch files in /usr/local/ -- they know it is exclusively for system administrators.)
Anyway, the ./configure --prefix /path/to/new/prefix will set a variable in the Makefile that is available when compiling the program, modifying the manual pages so they point to the correct locations for files, modifying configuration files, etc. So make will build the software specifically for the install location you want and make install will install it into that location.
Most programs can run even without the final make install step -- just ./program_name will often start them up. This is definitely a per-project thing -- some, like postfix, qmail, etc., are made up of many different moving pieces and rely on them all working together. Others, like ls or su might be self-contained enough to execute fine from the directory they were built in. (This is not often useful -- but sometimes very useful.)
However, not all projects use the Autotools -- they are huge, complicated, and miserable to maintain. Hand-written Makefiles are much simpler to write, and I personally think just distributing a simple Makefile with configuration variables available is a lot easier on developers and users both. (Though the ./configure ; make ; make install mantra is really easy on users when it works.)
Avoid making local installs into system directories. The system directories eg /usr, are reserved for the package management system to use. By definition, if you are doing make install that means you are making a local install, and if you need to do sudo make install that means you don't have permission to wherever you are writing.
So, if you are getting permission errors with make install, check and see whether you are trying to install into system directories, and install into /usr/local or similar instead. /usr/local is reserved for local installations. You may need to give yourself permission to write to /usr/local, but this is usually easily done. On Debian this can be done by adding yourself to the staff group. Better still, find or create a binary package, and install that instead. That way you can easily keep track of installed packages and obtain the other benefits of package management.
Note that the package management system conversely does not install into /usr/local, per the FHS. See Section 9.1 of the Debian Policy Manual- File system hierarchy for an overview.
As has been answered above, sudo make install lets you install the files in directories which are otherwise read-only to you as a user.
The problem I can foresee is that at a later date you may want to uninstall or upgrade the program. If you still have the source code directory tree then a make uninstall will uninstall the program for you but if, as many other typical users, you had deleted the source code directory tree then you are out of luck. And since you have not installed the program using a package management system, you may also be unable to uninstall the program that way.
The best way to install such programs may be to install them in your home directory. Pass the option --prefix=/home/<user>/<some>/<directory> to ./configure. This will allow you to use make install instead of sudo make install since /home/<user>/<some>/<directory> is writable by you. Also uninstallation is a snap -- rm -rf /home/<user>/<some>/<directory>
Because each step does different things
Prepare(setup) environment for building
./configure
This script has lots of options that you should change. Like --prefix or --with-dir=/foo. That means every system has a different configuration. Also ./configure checks for missing libraries that should be installed. Anything wrong here causes not to build your application. That's why distros have packages that are installed on different places, because every distro thinks it's better to install certain libraries and files to certain directories. It is said to run ./configure, but in fact you should change it always.
For example have a look at the Arch Linux packages site. Here you'll see that any package uses a different configure parameter (assume they are using autotools for the build system).
Building the system
make
This is actually make all by default. And every make has different actions to do. Some do building, some do tests after building, some do checkout from external SCM repositories. Usually you don't have to give any parameters, but again some packages execute them differently.
Install to the system
make install
This installs the package in the place specified with configure. If you want you can specify ./configure to point to your home directory. However, lots of configure options are pointing to /usr or /usr/local. That means then you have to use actually sudo make install because only root can copy files to /usr and /usr/local.
Now you see that each step is a pre-requirement for next step. Each step is a preparation to make things work in a problemless flow. Distros use this metaphor to build packages (like RPM, deb, etc.).
Here you'll see that each step is actually a different state. That's why package managers have different wrappers. Below is an example of a wrapper that lets you build the whole package in one step. But remember that each application has a different wrapper (actually these wrappers have a name like spec, PKGBUILD, etc.):
def setup:
... #use ./configure if autotools is used
def build:
... #use make if autotools is used
def install:
... #use make all if autotools is used
Here one can use autotools, that means ./configure, make and make install. But another one can use SCons, Python related setup or something different.
As you see splitting each state makes things much easier for maintaining and deployment, especially for package maintainers and distros.
First, it should be ./configure && make && make install since each depends on the success of the former. Part of the reason is evolution and part of the reason is convenience for the development workflow.
Originally, most Makefiles would only contain the commands to compile a program and installation was left to the user. An extra rule allows make install to place the compiled output in a place that might be correct; there are still plenty of good reasons that you might not want to do this, including not being the system administrator, not want to install it at all. Moreover, if I am developing the software, I probably don't want to install it. I want to make some changes and test the version sitting in my directory. This becomes even more salient if I'm going to have multiple versions lying around.
./configure goes and detects what is available in the environment and/or is desired by the user to determine how to build the software. This is not something that needs to change very often and can often take some time. Again, if I am a developer, it's not worth the time to reconfigure constantly. More importantly, since make uses timestamps to rebuild modules, if I rerun configure there is a possibility that flags will change and now some of the components in my build will be compile with one set of flags and others with a different set of flags that might lead to different, incompatible behaviour. So long as I don't rerun configure, I know that my compilation environment remains the same even if I change my sources. If I rerun configure, I should make clean first, to remove any built sources to ensure things are built uniformly.
The only case where the three command are run in a row are when users install the program or a package is built (e.g., Debian's debuild or RedHat's rpmbuild). And that assumes that the package can be given a plain configure, which is not usually the case for packaging, where, at least, --prefix=/usr is desired. And pacakgers are like to have to deal with fake-roots when doing the make install part. Since there are lots of exceptions, making ./configure && make && make install the rule would be inconvenient for a lot of people who do it on a far more frequent basis!
I just finished up installing ruby on a CentOS system and I can't for the life of me understand why I had to do these three steps. I googled around and it seems that this is the build system that all linux applications use. How does it work? And why execute three steps, why not just do 'make install'?
(I'm a java developer so I have very limited linux knowledge)
Very new to Linux. Been using Raspbian on my pi for a couple months. I've been successful in installing software from source. I've been noticing that whenever I use apt-get install it is so much easier and usually works without some fussing.
I usually try to save questions for Reddit until I'm out of Googling ideas, but where can I find a great place to find apt-get software and understand it?
Most of my programming experience has been through web languages so I'm clueless when it comes to compiling. When I tried to install Apache through make, make install it was unsuccessful. I'm not sure why, but when I attempted the same feat with apt-get it worked perfectly. Why is that?
Thanks :)
make looks for the first target in the Makefile. (GNU Make allows configuring this.)
make install looks for a target named exactly "install".
Make install is one of various possible targets in a Makefile. As a simple example, the other very common one is clean: make clean, in general, cleans temporary files which are necessary/useful by-products of the compilation process, but which are no longer needed once the final executable has been produced.
Make install contains the instructions to insert the compiled product into the system, for instance by running the necessary depmod command which takes care of a module installation.
then why ones have to run both?!
Because the first one can be executed as a normal user, the second often requires system privileges.
If your next question is: then why not run both as sudo, then the answer is that not all installations are going to be used system-wide. For instance, if you do not have root privileges on a system you have access to, you may wish to compile and install a given package for your own exclusive use. In this case, you want to be able to compile it and pass it to the linker, but you cannot install it for use by all system users. In this case, the reason for the difference is obvious.
In other words, each stage of the installation process is organized so that it can be executed with the lowest possible privileges, which allows both system-wide and local installations, whenever this makes sense.
Technically, there is no reason why not - this really is based on how the makefile was set up. It is all designed around dependencies. If the 'install' target is made dependent on the rest of the product, then it would implicitly build the product as you are thinking.
The reason they are separated out is that you are usually going to do a 'make' as the unprivileged developer, and do the 'make install' with elevated privs. Usually you don't want to mix those actions.
The 2 commands do different things.
make - this reads the makefile for instructions on how to compile the sources. It builds the program and the end result is your binaries.
make install - this reads the makefile for the target install directory, and places the files created by make into their appropriate directories.
dpkg is a program on a Debian/Ubuntu or any derivative distribution for installing already packaged applications. The Difference is very simple, a .deb file is a compiled package of application binaries. It has inbuilt logic for placing the different files indifferent directories.
For example, the executable for the application goes into /usr/bin, However the point to note here is that .deb is a packaged binary file which contains compiled software. You do not get to see the source, Hence Many Companies tend to publish their proprietary software in .deb/.rpm format.One such example is Insync, another is Crossover for Linux. Both these are proprietary but distributed as a .deb or a .rpm file.
Here is the gist.
dpkg -i
Means you are installing a compiled and packaged application to run on any Linux distribution which uses .deb format for installing packages.
and
./configure make make install
Means that you have the source code for the application which you are installing. You are now compiling manually by using the compiler(configure and then followed by make.) on the system rather than the package manager. The make install command will then install the software on the system. this method works regardless of the distribution you are installing on.
Well, both methods don't have auto updating. They suggest adding an apt repository with the .deb which is updated by a package maintainer. Then when you do system updates, the program will be updated alongside your other .deb packages. dpkg is the Ubuntu default package manager because it's derived from Debian. The whole system is installed using it.
Why do that many projects recommend to push compiled binaries to the filesystem root?
edit Ok. I might have been wrong. My /usr/local ist empty. If stuff only gets installed there, my argument is invalid. I still feel pretty insecure about doing a make install, because it at least could conflict with the system installation.
Thanks for answering. /edit
I have a folder ~/usr where I push all compiled stuff. I then do cmake -DCMAKE_INSTALL_PREFIX=$HOME/usr/ or ./configure --prefix ... and then install that without sudo. Some big projects I compile even have their own prefix.
Sure you have to tell your users to have ~/usr/bin in your PATH. I also added that to my LD_LIBRARY_PATH and PKG_CONFIG_PATH. But IMO that should be a default thing to do for Linux users (who compile stuff).
Polluting your distro installation with random crap is a sure way to get issues later. Its far worse then anything you can do to install Software on Windows.
I mean compiling a bleeding edge kicad, inkscape or jpeg-xl is easy. But will probably trash your system if you already have an older version installed.
(Some projects tell you to build a distro package and sudo install that. Much better, but I still prefer having the binaries in my own prefix. Also a lot got better, since many big projects publish daily snapshots as Appimage or similar.)
edit2 I was of course talking about a single-user system for users who sometimes like to test bleeding edge software. Not Multi-user sytems. Not Grandma, who's not allowed to install stuff. edit