When installing something from source (say, Ruby 1.9.2), what command can I run to get a complete list of all the dependencies needed to install that application? Is this possible?
4 Answers
Short answer: not possible. The difficulty of getting the exact dependencies from a source distribution is the reason why package management is so popular on Linux (okay, one of several reasons). In fact, if you just need to get it done and don't care so much how, the most reliable way to get the dependencies will probably be to grab a distro package (gentoo ebuilds are easy to work with) and pull the list of dependencies from that.
Otherwise, if you're lucky, the maintainers will have created a listing of the dependencies in the README file or similar - that'd be the first place to check. Failing that, if it's a C project and you don't mind getting your hands dirty, you can look inside the configure script (or better yet the configure.ac or whatever it's generated from) and figure out the dependencies from that based on what it checks.
Building from source
There isn't any programmatic way that I'm aware of, I generally look through the release notes and/or software README files to get a general idea. This works out to be an iterative process where I might find a library or two that I don't have or missed and need to go get them.
Building using a package manager
If on the other hand you're using a package manager such as apt
or yum
then you can enlist the help of these systems to help install all the dependencies ahead of time, prior to installing/building the package in question.
apt based distros
$ sudo apt-get build-dep <package>
yum based distros
$ sudo yum-builddep --nogpgcheck <source package>
-or-
$ sudo yum-builddep --nogpgcheck <package>
-
following commands install all required tools which is required to compile packages in RHEL/CentOS.
yum groupinstall "Development Tools" "Development Libraries"
but the issue.. is that it also install packages those are not required, and will take time to install Commented Nov 10, 2013 at 20:32 -
@RahulPatil - true installing that group will likely install most of what you might need, but there are a lot of other packages that aren't installed by this group that you'll often times still need to install them manually.– slm ♦Commented Nov 10, 2013 at 20:45
On the whole, I also can't give you a 100% solution, but for most sources using autotools, you can grep configure.ac
for AC_SEARCH_LIBS
, AC_CHECK_HEADERS
and PKG_CHECK_MODULES
.
The first argument of AC_CHECK_HEADERS
is a filename or even a path with a filename.
PKG_CHECK_MODULES
is introduced with pkg-config and, IIRC the second argument to PKG_CHECK_MODULES
includes a package name for which a file <pkg-name>.pc
must exist.
The second argument to AC_SEARCH_LIBS
is a library name and using Linux you are looking for a file which begins with lib<second-argument-to AC_SEARCH_LIBS>.so
.
Neither of those are perfect and this needn't give you a complete list of requirements, but ...
the source maintainers have an increased interest to see that these three things will lead you to a complete list of requirements.
with a little scripting you can use these three things to search through the packages of your distribution and find packages providing you with missing files. For instance using
apt-file search
for all Debian based Linuxes, as mentioned by Faheem Mitha.