34

I like how you can manage dependencies with pip requirements. Is there something similar in case of apt-get?

http://www.pip-installer.org/en/latest/requirements.html#requirements-file-format

Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93

4 Answers4

40

Your question is that you want to have a list of system dependences in one file, for being able to install it with one command.

I don't recomend you to include the version of a package in the system dependencies. In the soft system dependences like "build-essential" or "uuid-dev" you normally want the latest version of the package. In the "hard dependeces" like python, postgres or whatever, normally the version is specified in the name of the package itself, like "python2.6-dev" or "postgresql-8.4". Another problem you may have defining the exact version of the package is that maybe the version 8.4.11-1 of postgresql-8.4 will not be available in the repository in three months or in a year, and you will end up installing the current version in the repo.

Example. You can create a file named "requirements.system" with the system packages you need for you project:

python-virtualenv
python2.6-dev
uuid-dev
python-pip
postgresql-8.4

Then, in your INSTALL file explain how to install the system packages.

# Install system depencences by running
cat ~/project/install/requirements.system | xargs sudo aptitude install

We have running this configuration for about two years, having to recreate the enviroment from the scrach a few times and we never had a problem.

krenel
  • 776
  • 6
  • 7
  • 6
    You can also add the version number for the package, in a similar way to pip by using `package_name=version` (`python-virtualenv=1.7.1.2-1`). However, it may not be as useful as with pip because the Debian mirrors do not maintain as many older package versions as the PyPI repository. – C2H5OH May 13 '12 at 23:45
  • 1
    Sometimes you want to specify the version because some dpkg are really really bad. I remember memecache or similar required some outdated version or it will fail to install. It's a corner case, so sometimes it's a good thing. Also, if your system is known to be good in a particular state, you want to reproduce that state. If you need the latest, the standard deployment workflow is you create a new environment from scratch using the requirements you specify (but with the latest version), and tests it. – CppLearner Jan 10 '13 at 02:57
  • 8
    No need for cat: `xargs apt-get install – arand Aug 04 '14 at 08:45
9

We use the aptfile format at work. It's simply a bash wrapper with some helpers built-in.

Jose Diaz-Gonzalez
  • 2,066
  • 1
  • 15
  • 19
2

I usually create a list of installed packages with apt list --installed | awk -F/ '{print $1}' | grep -v Listing... > installed_packages.txt.

Explanation:

  • apt list --installed echoes a list of currently installed packages including versions
  • awk -F/ '{print $1}' gets rid of the package versions, this makes the file independent of your distribution (downstream compatibility between Mint, Ubuntu, Debian stable/testing, upstream not neccessarily)
  • grep -v Listing... gets rid of the "interactive" display of apt (first line)
  • all of that is then piped to a single file

You can then install on another system via cat installed_packages.txt | xargs apt install -y using each line of said file as an argument for apt.

-3

Since apt accepts input from stdin the simplest way to do it is:

$ cat requirement.txt
gcc
cmake

$ apt install < requirement.txt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Pasqo
  • 3
  • 1
  • 1
    As far as I can tell, this does precisely nothing, or rather, it does the same thing as `apt install ""` and will not install anything. – Daniele Procida Nov 28 '20 at 23:30