Difference between revisions of "Build Samba from Source"

m (Updated link)
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Introduction =
 
= Introduction =
  
Usually most users run [[Distribution_specific_package_installation|packages shipped with their distribution]] or created by 3rd parties, like SerNet ([http://www.samba.plus/older-packages/ Enterprise]/[http://www.samba.plus Samba+]), there are those out there, who want/need to compile Samba themselves. Common reasons are that the packages shipped with the distribution are old or not available for your platform, or you have [https://bugzilla.samba.org/ reported a bug] and got a patch from a developer to test, before it is included in the next official release. There are many reasons why users compile Samba. This documentation should still users fears about compiling Samba. Basically it's done with a few steps:
+
Most users are running [[Distribution-specific_Package_Installation|packages shipped with their distribution]] or from 3rd parties, such as SerNet ([http://www.samba.plus Samba+]/[http://www.samba.plus/older-packages/ Enterprise]). However, in some situations you decide to compile Samba yourself, like
 +
* outdated packages are shipped with your distribution
 +
* no packages are available for your distribution or OS
 +
* you want to apply a patch from a developer to fix a problem before a new version is released
  
* Install all [[Operating_system_requirements/Dependencies_-_Libraries_and_programs|dependencies (e. g. libraries)]] via the package manager of your distribution
+
Compiling Samba requires only a few steps:
 +
* Install all dependencies. See [[Package Dependencies Required to Build Samba]].
 
* Download the sources from [https://www.samba.org samba.org]
 
* Download the sources from [https://www.samba.org samba.org]
 
* Extract the source package
 
* Extract the source package
 
* Run
 
* Run
:./configure
+
:<code>./configure</code>
:make
+
:<code>make</code>
:sudo make install
+
:<code>sudo make install</code>
  
Even if there are a few more things to mention and to know, you will see that compiling Samba is not sorcery. ;-)
+
You can run most of the required steps in this documentation without root privileges. If root permissions are required, the command is prefixed with <code>sudo</code>. Please see the <code>sudo (8)</code> manual page and your distribution documentation how to set up <code>sudo</code>.
  
All the steps in this documentation should be run without root privileges, except where mentioned, in which case they are prefixed with sudo. You should consult other documentation on setting up sudo.
+
The following documentation is valid for every type of Samba installation, like an Active Directory (AD) domain controller (DC), a domain member (AD and NT4 domain), an NT4 PDC, and standalone server.
  
The following is suitable for any kind of Samba installation: Samba Active Directory Domain Controller, Member Server (AD + NT4 domain), Samba NT4 PDC, etc.
 
  
  
  
  
 +
= Samba Operating System Requirements =
  
= Samba operating system requirements =
+
To build Samba, install all required libraries and tools first. See [[Operating_System_Requirements|Operating System Requirements]].
  
Samba requires libraries and other software to compile and run. The first task is to install all these [[Operating system requirements|requirements]].
 
  
  
  
  
 +
= Obtaining Samba =
  
= Obtaining Samba =
+
== Stable Version (Recommended) ==
 +
 
 +
Always download the latest version of Samba from https://www.samba.org/.
  
== Stable version (recommended) ==
+
Samba maintains three series of minor versions. For a maximum of security and stability, the Samba team recommends that you only install the latest available version of a series. Older versions do not contain the latest bug and security fixes. For further information, see [[Samba_Release_Planning|Samba Release Planning]].
  
Download the latest version of Samba from https://www.samba.org/. It is always recommended to install the latest version of the [[Samba_Release_Planning#Current_Stable_Release|current stable release]]. If you need to use a previous series, always choose the last version from the [[Samba_Release_Planning#Maintenance_Mode|maintainance mode series]] or at least from the [[Samba_Release_Planning#Security_Fixes_Only_Mode|security-fixes-only mode]]. Older versions may not contain all improvements, bug and security fixes. If you ask for help, e. g. on the [https://lists.samba.org/mailman/listinfo/samba Samba Mailing List], you will typically be told to try a recent version, to ensure that you didn't hit a bug, that has been fixed in the meantime. Further information about the Samba release planning and supported release lifetime, can be found on the [[Samba_Release_Planning|Samba release planning]] page.
+
{{Imbox
 +
| type = note
 +
| text = In case if you are asking for help on the [https://lists.samba.org/mailman/listinfo/samba Samba Mailing List] and not running the latest version, the list members usually advice you to update your installation first to verify that the bug has not been fixed in the meantime.
 +
}}
  
Download example:
+
To download, use a tool like <code>wget</code>. For example:
  
 
  $ wget <nowiki>https://download.samba.org/pub/samba/stable/samba-x.y.z.tar.gz</nowiki>
 
  $ wget <nowiki>https://download.samba.org/pub/samba/stable/samba-x.y.z.tar.gz</nowiki>
Line 41: Line 50:
  
  
== Development version ==
+
== Development Versions ==
  
'''Not recommended for production usage!'''
+
'''Do not use a development version in production!'''
  
See [[Obtaining_a_Samba_development_version|Obtaining a Samba development version]].
+
To download a development version, use <code>git</code> to clone the repository. For details, see [[Using Git for Samba Development]].
  
 +
Before a new major version is released, the Samba team publishes release candidates for testing purposes. You can download release candidates from https://download.samba.org/pub/samba/rc/
  
  
  
  
= Extracting the source package =
 
  
Extract the downloaded source package into the current directory:
+
 
 +
= Extracting the Source Package =
 +
 
 +
To extract the downloaded source package, run:
  
 
  $ tar -zxf samba-x.y.z.tar.gz
 
  $ tar -zxf samba-x.y.z.tar.gz
Line 63: Line 75:
 
= configure =
 
= configure =
  
Step into the directory with the extracted sources:
+
Change into the directory with the extracted sources:
  
 
  $ cd samba-x.y.z/
 
  $ cd samba-x.y.z/
  
 
+
The <code>configure</code> script is located in the root of the sources directory. The main purpose of the script is to create a <code>Makefile</code> which is used by the command <code>make</code>. The <code>configure</code> script enables you to set various options, like installation paths. If you do not want to [[#Customizing_the_Configure_Options|customize]] any paths, and enable or disable parts of Samba, run the following command without any option:
Here you need to run the "configure" script. Its main purpose is to create a "Makefile", that is used by "make" for compilation, but it also allows you to set various parameters, like paths where the binaries should be installed. If you don't want to [[#Customize_configure_options|customize]] any paths or enable/disable parts of Samba that should be build, it's sufficient to run the command without any options:
 
  
 
  $ ./configure
 
  $ ./configure
  
 +
If the command fails, read the error message and fix the problem. One common problem are missing dependencies. For details, see [[Operating_System_Requirements|Operating System Requirements]].
  
If anything fails - usually because of missing [[Operating system requirements|dependencies]] - read the error message and fix the problem. The following example error indicates, that the GnuTLS headers are are not found:
+
The following example shows the output, if the <code>configure</code> script cannot find the GnuTLS headers:
  
 
  Checking for gnutls >= 1.4.0 and broken versions : not found
 
  Checking for gnutls >= 1.4.0 and broken versions : not found
Line 79: Line 91:
 
  GnuTLS (eg libgnutls-dev, gnutls-devel) for ldaps:// support and for the BackupKey protocol
 
  GnuTLS (eg libgnutls-dev, gnutls-devel) for ldaps:// support and for the BackupKey protocol
  
 
+
If the <code>configure</code> script exits without an error, you see the following output:
If all checks are done and nothing is missing, "configure" finishes with an appropriate message:
 
  
 
  'configure' finished successfully (1m2.432s)
 
  'configure' finished successfully (1m2.432s)
  
In this case, continue with the next step: [[#make|make]]
+
Continue with the <code>[[#make|make]]</code> step, if no error has occurred.
  
  
  
== Customizing configure options ==
+
== Customizing the Configure Options ==
  
Even if running "./configure" without any options is sufficient, you may want to adapt some of the paths or enable/disable features. For that, first make yourself familiar with the list of possible options:
+
While running the <code>configure</code> script without any options is sufficient to build Samba, you can customize installation paths and enable or disable features. To display the list of options, run:
  
 
  $ ./configure --help
 
  $ ./configure --help
  
The output is quite long, but there are mainly two important parts of options:
+
The output shows two major kind of options:
 
+
* [[#enable.2Fdisable.2Fwith.2Fwithout_options|--enable/--disable and --with/--without options]]
 +
* [[#Installation_directories|installation directories]]
  
  
=== enable/disable/with/without options ===
 
  
There are many "--enable-*/--disable-*", as well as "--with-*/--without-*" options. They allow you to turn on features that should be build, and to turn off for those that shouldn't. Each of the options can be turned to its opposite, by switching "enable" to "disable" and "with" to "without" and vice versa. Here are some examples:
+
=== enable/disable/with/without Options ===
  
 +
The <code>configure</code> script provides several <code>--enable-*</code> / <code>-disable-*</code> and <code>--with-*</code> / <code>--without-*</code> options. They allow you to enable and disable features. Each option you can turn to its opposite if you use <code>--enable</code> instead of <code>--disable</code>, <code>--with</code> instead of <code>--without</code>, and the other way around.
  
 
* <u>Example 1:</u> Disable CUPS support (enabled by default):
 
* <u>Example 1:</u> Disable CUPS support (enabled by default):
Line 108: Line 120:
 
           Build with cups support (default=yes)
 
           Build with cups support (default=yes)
  
:If you don't require support for CUPS, you can disable it by adding "--disable-cups" to the configure command:
+
:If you do not require CUPS support, disable the feature passing the <code>--disable-cups</code> option to the <code>configure</code> command:
  
  $ ./configure ..... --disable-cups
+
  $ ./configure ... --disable-cups
  
 
+
* <u>Example 2:</u> Compile Samba without AD DC capabilities:
* <u>Example 2:</u> Compile Samba without Active Directory Domain Controller capabilities:
 
  
 
  --without-ad-dc
 
  --without-ad-dc
 
           disable AD DC functionality (enables Samba 4 client and Samba 3 code base).
 
           disable AD DC functionality (enables Samba 4 client and Samba 3 code base).
  
: If you build Samba for a host that shouldn't be an AD DC, you can disable this function, by adding "--without-ad-dc" to the configure command:
+
: If you build Samba for a host that should not act as an AD DC, you can disable this feature passing the <code>--without-ad-dc</code> option to the <code>configure</code> command:
  
  $ ./configure ..... --without-ad-dc
+
  $ ./configure ... --without-ad-dc
  
 +
* <u>Example 3:</u> Build Samba with debug information:
  
* <u>Example 3:</u> Build with debug information, that may help to diagnose in case of failure:
+
$ ./configure ... --enable-debug  
  
$ ./configure ..... --enable-debug
 
  
 +
'''Warning: Do not enable or disable features if you have not fully understood the cause of the option! Changing options can prevent your Samba installation from working as expected!'''
  
'''Warning: Don't enable/disable features unless you know what you're doing! Changing options may prevent your Samba installation from working as expected!'''
 
  
  
 +
=== Installation Directories ===
  
=== Installation directories ===
+
If you use the default settings, the binaries, configuration files, libraries, and other files are installed in the <code>/usr/local/samba/</code> directory. This enables you to keep the complete Samba installation in one location. However, you can specify individual paths. For example:
  
By default, your whole Samba installation, including databases, smb.conf, etc., will be in /usr/local/samba/ (value of "--prefix="). This is good if you want to keep everything in one place, but you can also change some paths. Here are some examples:
+
* To install the daemon binaries like <code>smbd</code> and <code>samba</code> in the <code>/sbin/</code> directory instead of </code>/usr/local/samba/sbin/</code>, run:
 +
$ ./configure ... --sbindir=/sbin/
  
 +
* To set the default path to the </code>smb.conf</code> file to <code>/etc/samba/</code> instead of </code>/usr/local/samba/etc/</code>, run:
 +
$ ./configure ... --sysconfdir=/etc/samba/
  
* Install daemon binaries (smbd, samba, etc.) in /sbin/ instead of /usr/local/samba/sbin/
+
* To store the Samba man pages in the <code>/usr/share/man/</code> directory, run:
# ./configure ..... --with-sbindir=/sbin/
+
  $ ./configure ... --mandir=/usr/share/man/
 
 
 
 
* Set the default path for smb.conf to /etc/samba/ instead of /usr/local/samba/etc/
 
# ./configure ..... --with-sysconfdir=/etc/samba/
 
 
 
 
 
* Place the Samba man pages into a directory that is part of the systems manpath
 
  # ./configure ..... --mandir=/usr/share/man/
 
  
  
Line 154: Line 161:
 
= make =
 
= make =
  
The next step is quite simple. To start the compile process, run
+
To start the compilation, run
  
 
  $ make
 
  $ make
  
Depending of your number of CPU cores, you can run multiple jobs parallel (2 in the following example):
+
The <code>make</code> command is able to run multiple jobs in parallel. For example, to run 2 <code>make</code> sub-tasks at the same time, run:
  
 
  $ make -j 2
 
  $ make -j 2
  
If everything is successfully compiled, "make" finishes with an appropriate message:
+
If the compilation exits without an error, you see the following output:
  
 
  Waf: Leaving directory `/usr/src/samba-x.y.z/bin'
 
  Waf: Leaving directory `/usr/src/samba-x.y.z/bin'
 
  'build' finished successfully (9m3.667s)
 
  'build' finished successfully (9m3.667s)
  
In this case, continue with the next step: [[#make_install|make install]]
 
  
  
  
  
 +
= make test (Optional) =
  
= make test (optional) =
+
This optional step runs the Samba self test suite.
  
This step is optional and usually only interesting for developers.
+
$ make test
  
# make test
+
{{Imbox
 +
| type = note
 +
| text = You can only run the self test suite, if you built Samba using the <code>--enable-selftest</code> option.
 +
}}
  
runs the Samba selftest suite. It requires that Samba was built with --enable-selftest.
 
  
  
Line 187: Line 196:
 
= make install =
 
= make install =
  
The last step - the installation - needs to be run as "root" or via "sudo", to allow writing to the destination directories and setting permissions.
+
To install the compiled software, you require <code>root</code> permissions to write to the destination directories and set the correct permissions.
  
# make install
+
To install Samba, run:
 
Or if not running as root
 
 
   
 
   
  # sudo make install  
+
  $ sudo make install  
  
If everything is successfully installed, "make install" finishes with an appropriate message:
+
If the installation exits without an error, you see the following output:
  
 
  Waf: Leaving directory `/usr/src/samba-x.y.z/bin'
 
  Waf: Leaving directory `/usr/src/samba-x.y.z/bin'
Line 204: Line 211:
  
  
= Upgrading a source version =
+
= Adding Samba Commands to the $PATH Variable =
 +
 
 +
If you built Samba, add the directories containing the commands to the beginning of your <code>$PATH</code> variable. For example:
 +
 
 +
export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH
 +
 
 +
To permanently update your <code>$PATH</code>, see your distribution's documentation.
 +
 
 +
 
 +
 
 +
 
 +
 
 +
= Upgrading a Self-compiled Samba Installation =
 +
 
 +
To update a self-compiled Samba installation, run the same steps like for a new installation while using the same <code>configure</code> options.
 +
 
 +
 
 +
 
 +
 
 +
 
 +
= Applying a Patch =
 +
 
 +
Some situations require that you apply a patch to Samba. For example, a bug has been fixed and you you cannot wait until the new Samba version is released. To apply the patch to the Samba sources, run:
 +
 
 +
* Change into the Samba sources directory.
 +
$ cd samba-x.y.z/
 +
 
 +
* Download the patch. For example:
 +
$ wget -O /tmp/patch.txt <nowiki>https://bugzilla.samba.org/attachment.cgi?id=...</nowiki>
 +
 
 +
* Apply the patch to the sources:
 +
$ patch -p 1 < /tmp/patch.txt
 +
 
 +
* Recompile and install Samba. See [[Updating_Samba|Updating Samba]].
  
The steps are the same as for a new installation. For further information, see [[Updating_Samba|Updating Samba]].
 
  
  
Line 213: Line 252:
 
= Additional information =
 
= Additional information =
  
== Viewing build options of existing installations ==
+
== Viewing Built Options of an Existing Installation ==
  
If you already have Samba installed and want to see what options were used at build time, run the following command:
+
To display the options used to built Samba, run
  
 
  $ smbd -b
 
  $ smbd -b

Revision as of 16:33, 27 April 2017

Introduction

Most users are running packages shipped with their distribution or from 3rd parties, such as SerNet (Samba+/Enterprise). However, in some situations you decide to compile Samba yourself, like

  • outdated packages are shipped with your distribution
  • no packages are available for your distribution or OS
  • you want to apply a patch from a developer to fix a problem before a new version is released

Compiling Samba requires only a few steps:

./configure
make
sudo make install

You can run most of the required steps in this documentation without root privileges. If root permissions are required, the command is prefixed with sudo. Please see the sudo (8) manual page and your distribution documentation how to set up sudo.

The following documentation is valid for every type of Samba installation, like an Active Directory (AD) domain controller (DC), a domain member (AD and NT4 domain), an NT4 PDC, and standalone server.



Samba Operating System Requirements

To build Samba, install all required libraries and tools first. See Operating System Requirements.



Obtaining Samba

Stable Version (Recommended)

Always download the latest version of Samba from https://www.samba.org/.

Samba maintains three series of minor versions. For a maximum of security and stability, the Samba team recommends that you only install the latest available version of a series. Older versions do not contain the latest bug and security fixes. For further information, see Samba Release Planning.

To download, use a tool like wget. For example:

$ wget https://download.samba.org/pub/samba/stable/samba-x.y.z.tar.gz


Development Versions

Do not use a development version in production!

To download a development version, use git to clone the repository. For details, see Using Git for Samba Development.

Before a new major version is released, the Samba team publishes release candidates for testing purposes. You can download release candidates from https://download.samba.org/pub/samba/rc/




Extracting the Source Package

To extract the downloaded source package, run:

$ tar -zxf samba-x.y.z.tar.gz



configure

Change into the directory with the extracted sources:

$ cd samba-x.y.z/

The configure script is located in the root of the sources directory. The main purpose of the script is to create a Makefile which is used by the command make. The configure script enables you to set various options, like installation paths. If you do not want to customize any paths, and enable or disable parts of Samba, run the following command without any option:

$ ./configure

If the command fails, read the error message and fix the problem. One common problem are missing dependencies. For details, see Operating System Requirements.

The following example shows the output, if the configure script cannot find the GnuTLS headers:

Checking for gnutls >= 1.4.0 and broken versions : not found
/usr/src/samba-x.y.z/source4/lib/tls/wscript:37: error: Building the AD DC requires
GnuTLS (eg libgnutls-dev, gnutls-devel) for ldaps:// support and for the BackupKey protocol

If the configure script exits without an error, you see the following output:

'configure' finished successfully (1m2.432s)

Continue with the make step, if no error has occurred.


Customizing the Configure Options

While running the configure script without any options is sufficient to build Samba, you can customize installation paths and enable or disable features. To display the list of options, run:

$ ./configure --help

The output shows two major kind of options:


enable/disable/with/without Options

The configure script provides several --enable-* / -disable-* and --with-* / --without-* options. They allow you to enable and disable features. Each option you can turn to its opposite if you use --enable instead of --disable, --with instead of --without, and the other way around.

  • Example 1: Disable CUPS support (enabled by default):
--enable-cups
          Build with cups support (default=yes)
If you do not require CUPS support, disable the feature passing the --disable-cups option to the configure command:
$ ./configure ... --disable-cups
  • Example 2: Compile Samba without AD DC capabilities:
--without-ad-dc
          disable AD DC functionality (enables Samba 4 client and Samba 3 code base).
If you build Samba for a host that should not act as an AD DC, you can disable this feature passing the --without-ad-dc option to the configure command:
$ ./configure ... --without-ad-dc
  • Example 3: Build Samba with debug information:
$ ./configure ... --enable-debug 


Warning: Do not enable or disable features if you have not fully understood the cause of the option! Changing options can prevent your Samba installation from working as expected!


Installation Directories

If you use the default settings, the binaries, configuration files, libraries, and other files are installed in the /usr/local/samba/ directory. This enables you to keep the complete Samba installation in one location. However, you can specify individual paths. For example:

  • To install the daemon binaries like smbd and samba in the /sbin/ directory instead of /usr/local/samba/sbin/, run:
$ ./configure ... --sbindir=/sbin/
  • To set the default path to the smb.conf file to /etc/samba/ instead of /usr/local/samba/etc/, run:
$ ./configure ... --sysconfdir=/etc/samba/
  • To store the Samba man pages in the /usr/share/man/ directory, run:
$ ./configure ... --mandir=/usr/share/man/



make

To start the compilation, run

$ make

The make command is able to run multiple jobs in parallel. For example, to run 2 make sub-tasks at the same time, run:

$ make -j 2

If the compilation exits without an error, you see the following output:

Waf: Leaving directory `/usr/src/samba-x.y.z/bin'
'build' finished successfully (9m3.667s)



make test (Optional)

This optional step runs the Samba self test suite.

$ make test




make install

To install the compiled software, you require root permissions to write to the destination directories and set the correct permissions.

To install Samba, run:

$ sudo make install 

If the installation exits without an error, you see the following output:

Waf: Leaving directory `/usr/src/samba-x.y.z/bin'
'install' finished successfully (18.243s)



Adding Samba Commands to the $PATH Variable

If you built Samba, add the directories containing the commands to the beginning of your $PATH variable. For example:

export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH

To permanently update your $PATH, see your distribution's documentation.



Upgrading a Self-compiled Samba Installation

To update a self-compiled Samba installation, run the same steps like for a new installation while using the same configure options.



Applying a Patch

Some situations require that you apply a patch to Samba. For example, a bug has been fixed and you you cannot wait until the new Samba version is released. To apply the patch to the Samba sources, run:

  • Change into the Samba sources directory.
$ cd samba-x.y.z/
  • Download the patch. For example:
$ wget -O /tmp/patch.txt https://bugzilla.samba.org/attachment.cgi?id=...
  • Apply the patch to the sources:
$ patch -p 1 < /tmp/patch.txt



Additional information

Viewing Built Options of an Existing Installation

To display the options used to built Samba, run

$ smbd -b