Linux make install to directory

Make install, but not to default directories?

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.?

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 stackoverflow.com/a/17679654/313113

7 Answers 7

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.

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.

Erik, it looks like there will be references to the path you run make in anyway, if you build from source.

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.

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

 export DESTDIR="$HOME/Software/LocalInstall" && make -j4 install 

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/

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.

Читайте также:  Astra linux файлы другого пользователя

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. gnu.org/software/automake/manual/html_node/DESTDIR.html

@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.

Источник

Change the Install directory with make install

Generally, packages are installed in the default directory. Depending on the system’s Linux version, it might be necessary to use a different directory such as /usr or /user/local. We might also want to install a particular software application for a single user rather than for the entire system.

We’ll take a look at how to change where packages get installed by running make uninstall.

Using ./configure Parameters

When using autoconf/automake to build software packages, a configure script with several standard parameters and (sometimes) additional custom parameters is provided. Some packages don’t use autoconf but they usually offer a compatible ./configure script.

We can specify which directories make will create when we run ./configue by using parameters.

  • –prefix= − By default, this is usually /usr or usr/local, and it is the directory used for other settings.
  • –libdir= − This is the libraries directory, and it’s usually $ /lib or $ /lib64 by default
  • –bindir= − This is the executables directory, and it’s usually $ /bin by default

By default, the prefix parameter is used for both lib and bin directories. We can use the prefix argument to specify where we want to install our program.

When we want to ensure that a package follows our own structure, we can use GNU’s diffutil package as an example. It installs to /usr/lib by default. Let’s set prefix to /usr, and libdir to /usr/lib64 −

$ ./configure --prefix=/usr --libdir=/usr/lib64

Since we didn’t specify bindir, it defaults to /usr/bin because we specified prefix /usr. The prefix parameter doesn’t apply to directories we don’t set explicitly.

Читайте также:  Linux md5 file check

After running make install, the diffutil package will be installed into the desired locations. We’re going to install to /usr so we’ll need root privileges.

$ make install $ ls -l /usr/bin/diff -rwxr-xr-x 1 root root 1078184 Jun 6 11:21 diff

You can also change the installation directory so that it installs into your own personal folder instead of the system folder. Then, you won’t need root privileges to run the installer.

We’ll start by cleaning up the installation directory using make clean and then configure it to be installed into /home/tpoint/diffutils/usr −

$ make clean $ ./configure --prefix=/home/tpoint/diffutils/usr

When we change prefix, other parameters such us libdir and bindir use the /home/user/diffutil/usr as the base dirctory.

Using DESTDIR

When we run./configue, we’re changing the building and installing processes, so the installed files would be using those paths. For example, the application might need to install resources such as icons, sound files, and so on, and it must be able to locate them. Let’s look for the prefix inside the directory where we installed diffutils using —prefix=/path/to/dir.

$ strings /home/tpoint/diffutils/usr/bin/diff | grep /home/tpoint/diffutils/usr /home/tpoint/diffutils/usr/share/locale

We can see that strings were found in the path /home/user/bin/diffutils/usr inside the binary we just downloaded. It’s fine if we don’t install the new version at a different location.

We sometimes just want to install a program into another location without changing its internal folder structure.

An example would be when we want to create a tarball of an installed program and then copy it to another computer. If that happens, then we normally install the packages into an empty and temporary directory first. So, the package doesn’t need to mention this temporary address.

For proper execution, we will use the DESTDIR= environment variable when running make install. This path will be added into all installation directories. We’re going to uninstall diffutils from our system by removing its current installation and installing it again with DESTDIR.

$ rm -r /home/tpoint/diffutils $ make clean $ ./configure --prefix=/usr $ make $ make DESTDIR=/home/tpoint/diffutils install

Make will use /home/tpoint/diffutils as its installation location. We’ve configured DiffUtils to use /usr as its default directory. Here’s the result −

$ ls -l /home/tpoint/diffutils/usr/bin total 1740 -rwxr-xr-x 1 tpoint users 191456 Jun 6 12:48 cmp -rwxr-xr-x 1 tpoint users 1078184 Jun 6 12:48 diff -rwxr-xr-x 1 tpoint users 300552 Jun 6 12:48 diff3 -rwxr-xr-x 1 tpoint users 204376 Jun 6 12:48 sdiff $ strings /home/tpoint/diffutils/usr/bin/diff | /home/tpoint/diffutils

As we see, we installed the package in /home/tpoint/diffutils. This time, there is no reference to the directory specified by DESTDIR.

Читайте также:  Найти ip адрес линукс

Using Makefile Parameters

If a package does not contain a ./configure file, it may provide a makefile that uses GNU conventions. In this case, the parameters used for ./configure can be followed.

If we want to set a variable with make, we’ll use the parameter variable=value. Let’s change the prefix to /usr and libdir to /usr/lib64

$ make clean $ make prefix=/usr libdir=/usr/lib64 $ make prefix=/usr libdir=/usr/lib64 install

We need to recompile the package and then install it again using the same configuration.

Variables in the Makefile will be set up using./configure conventions, and the prefix variable will be used as the base location for other options.

We can now use DESTDIR in the same manner as we used PREFIX earlier. Doing so allows us to install the packages in any location without changing their structure. Let’s use prefix=/usr/local this time, and let’s add DESTDIR to install diffutils in /home/tpoint/diffutils −

$ rm -r /home/tpoint/diffutils $ make clean $ make prefix=/usr/local $ make prefix=/usr/local DESTDIR=/home/tpoint/diffutils install

First we remove the destination folder in case there are old copies of the app from the previous install. Let’s take a look at the results −

$ ls -l /home/tpoint/diffutils/usr/local/bin total 1740 -rwxr-xr-x 1 tpoint users 191456 Jun 6 22:59 cmp -rwxr-xr-x 1 tpoint users 1078184 Jun 6 22:59 diff -rwxr-xr-x 1 tpoint users 300552 Jun 6 22:59 diff3 -rwxr-xr-x 1 tpoint users 204376 Jun 6 22:59 sdiff $ strings /home/tpoint/diffutils/usr/local/bin/diff | /home/tpoint/diffutils

We installed diffutilis in /home/baeldung/diffutils using the path /usr/local. There are no trace files for the DESTDIR directory within the binary.

Only DESTDIR is in upper case, while PREFIX, LIBDIR, etc., are in lower case.

We can also use the Makefiles’ environment variable when the packages provide the ./configure script. If you’re using ./configure, then the make variable will take precedence over any configure parameter.

Conclusion

We learned how to set the location where packages get installed when they’re installed using make install.

Initially, we looked at executing the./configure command, then switched directories. If there is no./configure present, we can edit makefile variables instead.

Источник

Оцените статью
Adblock
detector