203

I want to run 'make install' so I have everything I need, but I'd like it to install the things in their own folder as opposed to the system's /usr/bin etc. is that possible? even if it references tools in the /usr/bin etc.?

jww
  • 97,681
  • 90
  • 411
  • 885
Jon Phenow
  • 3,974
  • 5
  • 26
  • 30
  • 3
    If you have already built the project and you ran ./configure without a prefix and you want to install it in a custom path, see http://stackoverflow.com/a/17679654/313113 – Alex Bitek Jul 08 '14 at 09:06

7 Answers7

277

It depends on the package. If the Makefile is generated by GNU autotools (./configure) you can usually set the target location like so:

./configure --prefix=/somewhere/else/than/usr/local

If the Makefile is not generated by autotools, but distributed along with the software, simply open it up in an editor and change it. The install target directory is probably defined in a variable somewhere.

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • 11
    shouldn't `make && make install` follow the configure clause? – nass Jun 26 '15 at 16:41
  • 3
    The problem i have with `--prefix` is that if you run a `strings` on the resulting binary afterwards, you see that the path is stored inside. I don't know why this happends, but I certainly dont want my machine paths on binaries that I ship to other users. –  Jan 20 '20 at 18:43
  • 1
    Erik, it looks like there will be references to the path you run make in anyway, if you build from source. – Konstantin Rybakov Jan 29 '20 at 07:32
  • 1
    This is the correct answer if you intend to run the software from the `/somewhere/else/than/usr/local`. If you instead wish to gather up the files in one directory (in preparation for creating a tarball or install package), but intend for them to eventually be installed and run from elsewhere, set prefix to the final install directory, and use DESTDIR to specify the staging directory. – pavon Jul 02 '21 at 17:04
86

Since don't know which version of automake you can use DESTDIR environment variable.
See Makefile to be sure.

For example:

 export DESTDIR="$HOME/Software/LocalInstall" && make -j4 install
Alex Bitek
  • 6,529
  • 5
  • 47
  • 77
Andor
  • 5,523
  • 5
  • 26
  • 24
  • 16
    This works when you ran configure without --prefix command line argument and you already built the project but you don't want to install it in the default locations but instead specify a custom installation path. This will append the default usr/local/bin/ path to the DESTDIR and your project will get installed into $HOME/Software/LocalInstall/usr/local/bin/ – Alex Bitek Jul 08 '14 at 09:10
  • 1
    This is a brilliant solution. I don't know why this is not the picked answer! Nearly all the other answers ask to re-configure, which means one needs to re-make also. Imagine having compiled after 2~3 hours the entire MITK superbuild and then be asked to redo it, just because I want to install the compiled files to a different location. This here is a wonderful work around to avoid that situation. – Duck Dodgers Feb 10 '19 at 22:32
  • The original question is ambiguous, but I think this answer is actually the correct one. DESTDIR is used to install the files to a specific place while the system is configured for the standard location. https://www.gnu.org/software/automake/manual/html_node/DESTDIR.html – David Dombrowsky Apr 16 '21 at 03:27
  • 1
    @AlexBitek DESTDIR won't always work in that situation. There may be cases where the software in question uses the --prefix set by configure when generating the contents of it's files (for example hardcoding the default path to look in for config files). DESTDIR is intended for gathering files into a temporary staging directory which you would use to build tarballs or install packages, and not for running directly out of that directory. It might work, or it might not, or there may be some caveats where the software uses relative paths for somethings, and absolute paths for others. – pavon Jul 02 '21 at 17:12
46
make DESTDIR=./new/customized/path install

This quick command worked for me for opencv release 3.2.0 installation on Ubuntu 16. DESTDIR path can be relative as well as absolute.

Such redirection can also be useful in case user does not have admin privileges as long as DESTDIR location has right access for the user. e.g /home//

samasat
  • 569
  • 4
  • 4
20

It could be dependent upon what is supported by the module you are trying to compile. If your makefile is generated by using autotools, use:

--prefix=<myinstalldir>

when running the ./configure

some packages allow you to also override when running:

make prefix=<myinstalldir>

however, if your not using ./configure, only way to know for sure is to open up the makefile and check. It should be one of the first few variables at the top.

Tree77
  • 473
  • 3
  • 10
  • 3
    you should also be aware that `make prefix=...` may result in binaries with wrong hard-coded paths, since those can usually not be modified after `./configure --prefix=...` – Tobias Kienzler Nov 20 '13 at 10:28
5

If the package provides a Makefile.PL - one can use:

perl Makefile.PL PREFIX=/home/my/local/lib LIB=/home/my/local/lib
make
make test
make install

* further explanation: https://www.perlmonks.org/?node_id=564720

MacMartin
  • 2,366
  • 1
  • 24
  • 27
1

I tried the above solutions. None worked.

In the end I opened Makefile file and manually changed prefix path to desired installation path like below.

PREFIX ?= "installation path"

When I tried --prefix, "make" complained that there is not such command input. However, perhaps some packages accepts --prefix which is of course a cleaner solution.

Majid Azimi
  • 907
  • 1
  • 11
  • 29
-8

try using INSTALL_ROOT.

make install INSTALL_ROOT=$INSTALL_DIRECTORY