Change the Install directory with make install

When building software packages from source, you often need to control where the compiled software gets installed. By default, packages are typically installed in standard system directories like /usr or /usr/local. However, you might want to install to a custom location for testing, creating packages, or installing software for a single user without requiring root privileges.

Using ./configure Parameters

Most modern software packages use autotools (autoconf/automake) which provides a ./configure script with standardized parameters for controlling installation directories.

Common Configure Parameters

  • --prefix=<dir> Base directory for installation (default: /usr or /usr/local)

  • --bindir=<dir> Directory for executables (default: ${prefix}/bin)

  • --libdir=<dir> Directory for libraries (default: ${prefix}/lib or ${prefix}/lib64)

  • --sysconfdir=<dir> Directory for configuration files (default: ${prefix}/etc)

Example: Installing to Custom Prefix

To install a package to /usr with libraries in /usr/lib64

$ ./configure --prefix=/usr --libdir=/usr/lib64
$ make
$ sudo make install

For personal installation without root privileges

$ ./configure --prefix=$HOME/local
$ make
$ make install

This installs the software to $HOME/local/bin, $HOME/local/lib, etc.

Using DESTDIR for Staging

DESTDIR is a special variable that prepends a directory path to all installation paths without changing the software's internal configuration. This is commonly used for package creation or testing installations.

$ ./configure --prefix=/usr
$ make
$ make DESTDIR=/tmp/package-staging install

The software will be configured to run from /usr, but files are actually installed to /tmp/package-staging/usr/bin, /tmp/package-staging/usr/lib, etc.

Verifying Installation Paths

You can check the compiled-in paths using the strings command

$ strings /tmp/package-staging/usr/bin/program | grep /usr
/usr/share/locale
/usr/lib/program

Using Makefile Variables

Some packages don't use autotools but provide Makefiles that accept GNU-style variables. You can set these variables directly with make

$ make PREFIX=/usr/local
$ make PREFIX=/usr/local install

Common Makefile variables include

  • PREFIX Base installation directory

  • BINDIR Executable directory

  • LIBDIR Library directory

  • DESTDIR Staging directory (same concept as with autotools)

Example: Custom Installation with Makefile

$ make clean
$ make PREFIX=/opt/myapp
$ make PREFIX=/opt/myapp install

Using DESTDIR for staging

$ make PREFIX=/usr/local
$ make PREFIX=/usr/local DESTDIR=/tmp/staging install

Comparison of Methods

Method Use Case Changes Binary Paths Requires Root
--prefix Permanent custom location Yes Depends on location
DESTDIR Package creation, staging No No
Makefile variables Non-autotools packages Yes Depends on location

Best Practices

  • Use --prefix when you want the software to permanently run from a custom location

  • Use DESTDIR for creating packages or testing installations without affecting the system

  • Always use the same variables for both make and make install commands

  • Check if ./configure --help lists additional directory options specific to the package

Conclusion

Controlling installation directories with make install provides flexibility for different deployment scenarios. Use --prefix and related configure parameters for permanent custom installations, and DESTDIR for staging installations without changing the software's internal configuration. Understanding these methods is essential for package maintainers and system administrators.

Updated on: 2026-03-17T09:01:38+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements