Compiling - How To Compile and Install Programs From Source - Unix & Linux Stack Exchange
Compiling - How To Compile and Install Programs From Source - Unix & Linux Stack Exchange
SPONSORED BY
This is an issue that really limits my enjoyment of Linux. If the application isn't on a repository
or if it doesn't have an installer script, then I really struggle where and how to install an
49 application from source.
Comparatively to Windows, it's easy. You're (pretty much) required to use an installer
application that does all of the work in a Wizard. With Linux... not so much.
35
So, do you have any tips or instructions on this or are there any websites that explicitly explain
how, why and where to install Linux programs from source?
Share Improve this question edited Sep 20 '12 at 2:31 asked Aug 10 '10 at 22:54
Follow Renan Nitrodist
16.6k 8 63 85 675 1 7 10
8 "Comparatively to Windows, it's easy. You're (pretty much) required to use an installer application that
does all of the work in a Wizard. With Linux... not so much." There's the weak point in the question.
With Windows, you rarely get the source code, so you're at the mercy of whomever made the package.
If you think about this, it's not that much different from saying "there was no Linux package, so I have
to build from source", ie. there wasn't a way to get it to begin with. Building from source is usually a last
resort in *nix-land, but rarely an option in Windows-ville. – Avery Payne Aug 12 '10 at 1:22
2 That being said... +1 bump for asking a common question that should be answered for all newcomers
to *nix systems :) Building from source sometimes means the difference between fixing a nasty bug and
https://unix.stackexchange.com/questions/173/how-to-compile-and-install-programs-from-source 1/6
08/12/2021 12:29 compiling - How to compile and install programs from source - Unix & Linux Stack Exchange
to nix systems. :) Building from source sometimes means the difference between fixing a nasty bug and
just suffering until the next software release. It's really not that bad, and as many here have pointed out,
once you know what to look for and how to do it, fairly painless. – Avery Payne Aug 12 '10 at 1:24
Normally, the project will have a website with instructions for how to build and install it.
Google for that first.
27
For the most part you will do either:
1. Download a tarball (tar.gz or tar.bz2 file), which is a release of a specific version of the
source code
2. Extract the tarball with a command like tar zxvf myapp.tar.gz for a gzipped tarball or
tar jxvf myapp.tar.bz2 for a bzipped tarball
Or:
1. Use git or svn or whatever to pull the latest source code from their official source
repository
Both configure and autogen.sh will accept a --prefix argument to specify where the software is
installed. I recommend checking out Where should I put software I compile myself? for advice
on the best place to install custom-built software.
Share Improve this answer Follow edited Apr 13 '17 at 12:36 answered Aug 10 '10 at 23:02
Community Bot Sandy
1 3,091 2 20 14
Why is autogen.sh used when getting the latest, but configure/make is used for an official release?
– Louis Salin Aug 10 '10 at 23:55
1 Typically people who want the "bleeding edge" software will pull the release from the version control
software (like git, subversion, or CVS). This is "bleeding edge" because it's probably untested, unlike a
released tarball, which has (probably) been vouched for as working (at least mostly). Make sense?
– Matt Simmons Aug 11 '10 at 2:30
2 @Matt, sure it makes sense but I think the comment was directed more at the fact that Sandy now
made it appear as if there's an autogen.sh in every git'd/svn'd trunk. – reiche Aug 11 '10 at 10:42
1 And a chicken in every pot...or something like that. Heck, every once in a while, I come across software
without a configure script, too. If there were an easy, unified way of doing it, we wouldn't need
packages ;-) – Matt Simmons Aug 11 '10 at 11:04
Matt is absolutely right, this is why I said "for the most part", and first advocated looking up the
project's website. The autogen.sh/configure advice will hold for pretty much every GNOME module, and
a ton of other projects too Some projects don't use automake and will only have Makefile and you
https://unix.stackexchange.com/questions/173/how-to-compile-and-install-programs-from-source 2/6
08/12/2021 12:29 compiling - How to compile and install programs from source - Unix & Linux Stack Exchange
a ton of other projects, too. Some projects don t use automake, and will only have Makefile, and you
will just run make && sudo make install . Some Python projects will only have a setup.py, which you
will call to install (since there is no real compile setup). There are plenty of other build/install systems
out there, too. Hopefully README or INSTALL files will explain exactly what to do. – Sandy Aug 11 '10 at
13:11
I just want to add that there are package managers that compile packages from source, and
handle all package dependencies, flags, etc..
7
In BSD systems it's ports : Using the Ports Collection
In Debian, the apt-get package manager can install from source too: APT HOWTO: Working
with source packages (Same goes for Ubuntu, Linux-mint and everything else based on
Debian)
The Gentoo distribution uses the portage package manager, which compiles the whole
system from source only: Portage Introduction.
Slackware can compile packages but I don't know if there's any package manager for this in
there.. =)
Anyway you can always compile packages manually like Sandy mentioned above =) Also it
must be possible to use apt-get or portage package managers in any other distro...
Share Improve this answer Follow edited Dec 13 '11 at 19:24 answered Aug 10 '10 at 23:14
Kevin holms
36.9k 14 83 111 257 4 9
1 To say "the apt-get package manager can install from source" is incorrect. The quoted section describes
how one can create a Debian package from Debian sources. Not arbitrary upstream sources.
– Faheem Mitha Dec 13 '11 at 19:45
I think it's just best to read the documentation coming with that specific program or
application that you're wanting to install. Usually there are readmes/READMEs inside the
2 tarballs (the application source archive which you can usually download) or maybe even
INSTALL files to read and learn about what is the preferred way of installing said application. In
short: RTFM ;)
I came here because the the README gave all the requirements to build under Linux, but only has
Windows install instructions. The accepted answer worked for me and probably works most of the time.
I think it's almost better advice to try the ./configure route and go to the README if it doesn't work (i.e.
missing a dependency and you can't read the compiler output). – Stephen C Mar 21 '18 at 14:52
https://unix.stackexchange.com/questions/173/how-to-compile-and-install-programs-from-source 3/6
08/12/2021 12:29 compiling - How to compile and install programs from source - Unix & Linux Stack Exchange
1 Find Port
Ports are organized by category so if you don't know what category the port is in you have to
find it first:
cd /usr/ports
make search name=myport
Sometimes there are too many entries that way. I personally prefer:
Use the * when searching since there are often multiple versions of a port available. The
depth argument ensures your return results aren't needlessly cluttered with matches you are
unlikely to want.
Configuration
Often, you'll want to do some configuration; software such as Apache and Postgres practically
require it. There are three main choices: command line, environment and make configuration
files. To get started with the command line:
make showconfig
this will list the default configuration options. If you like the defaults you are ready to compile
and install. If not,
make config
will bring up a dialog box where you can select which options you want. (Don't become
confused with this and make configure which configures your port with your chosen options!)
This is often sufficient but for some software, like Apache, there is often complex configuration
that a simple dialog won't handle. For this, you also should look at the Makefile(s) which will
sometimes give you some additional targets for make that will give you more information. To
continue the Apache example
make show-modules
make show-options
make show-categories
will give you information on setting up you chosen modules, thread options and the like. If
your port's defaults are mostly fine and you just want to change a few things, you can also just
pass key=value pairs like environment variables:
For complex configuration however the command line won't work well and you're better
neither of the first two methods will be effective. In this case you can make a configuration file
and pass that to make with the __MAKE_CONF variable. FreeBSD has a default configuration
file: /etc/make.conf which usually contains information on previously installed ports and
other system settings. To begin, create a file with your ports options, call it ~/myport.mk and
then combine that file with /etc/make.conf:
BEWARE! If you need to adjust your configuration settings after make configure or an
installation in whole or part you absolutely must clear your configuration first:
make rmconfig
Failure to do so will result in unexpected interactions between the ports subsystem, your port's
make defaults and your desired configuration.
That's kind of a lot for a summary, but the complexity of configuration is mostly about the
app, not the port. Bash for example, doesn't really have any options.
Installation
or you can
make build
make install
make clean
That's pretty much it. Obviously there is more you can do such as recursively listing
dependencies and configuration options, update with patches and so on. Here I will refer you
to the Ports section of the Handbook, the port subsystem's man page (good info on additional
make targets) and the make man page.
Recently I've started using "Checkinstall" when installing from source outside of my package
manager. It builds a "package" from a 3rd party tarball which can then be installed and
0 managed (and uninstalled) through your package manager tools.
aryeh
151 2
https://unix.stackexchange.com/questions/173/how-to-compile-and-install-programs-from-source 6/6