Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If someone used a Python virtualenv he knows we can run scripts in its own environment installing all necessary libraries which won't impact main python distribution.

Do we have something similar in a Linux (Debian) world for make utility?

  1. Case 1: I downloaded sources and I know what dependencies I need. I put libraries somewhere in home directory and I explicitly say to make utility where to search them.
  2. Case 2: I run some kind of virtualenv for make utility and I call there apt-get install lib-required-dev so downloaded libraries would be placed in this virtual environment and won't pollute my OS. And then I run make.
share|improve this question

2 Answers 2

up vote 4 down vote accepted

Case one is relatively easy, at least for some programs. Most source packages include a configure script which checks for the availability of needed libraries. These scripts will generally have options to specify search paths. For example --lib-prefix. That way, you don't even need to modify the Makefile yourself. Now whether, or not this will work will depend on how complex the dependencies are, but it's worth a try.

For option 2, you have the chroot program:

   chroot - run command or interactive shell with special root directory

chroot needs certain files and directories to be present. The details will depend on what exactly you need to do (e.g. do you need /dev? Do you need /proc?). You can get a minimal chroot environment like this (as root):

mkdir foo
cp -r /bin /lib /lib64 foo/
chroot foo

The last command will move you into the directory foo and run your default shell treating foo as /. The procedure I have outlined is a simplification. You don't need everything in /lib for example. You will also probably need more directories to be present depending on what you want to do. Finally, you can also use mount bind to link the directories into the chroot environment but not if you want it to be completely independent of your real OS.

An easy way of creating such a playground is to take a small partition and install a minimal system onto that partition. You can then simply make the chroot like so (always as root):

mount /dev/sda2 foo/
chroot foo/

Obviously, change sda2 to whichever partition you installed your minimal system on. For more information see these links:

share|improve this answer
    
I haven't tried but it looks the most suitable solution for me –  Druid Oct 3 '13 at 7:36

terdon's answer is spot on.

Another, somewhat more involved but more durable approach, would be to actually create a virtual environment (virtualbox is my go to here.) Create a new virtual machine with a basic/standard version of the OS you're using, save the state of that machine, and set about installing whatever dependencies as if you were on a regular system. When you're finished compiling, you can then reset the VM back to it's original state.

It's worth noting that while you can absolutely do this headless i.e. in a remote, server environment, it's much easier to create the VM on a local machine (or a remote machine with a forwarded X session.) Once you have a good base VM that you know how to access, you can then export the VM.

share|improve this answer
    
+1 Your comment about exporting the VM intrigues me. Can you please elaborate? –  Joseph R. Oct 2 '13 at 22:58
    
I was thinking about it as the last solution. But I wanted to have something like chroot. But definitely your answer is 100% valid. Thanks. –  Druid Oct 3 '13 at 7:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.