Variants are a way for port authors to provide options for a port that may be chosen at installation. Typically, variants are optional features that can be enabled, but are not necessarily useful for all users and are thus not enabled by default. To display the available variants for a port, if any, use this command:
$ port variants portname
For example:
$ port variants apache2
apache2 has the variants: eventmpm: Use event MPM (experimental) * conflicts with preforkmpm workermpm openldap: Enable LDAP support through OpenLDAP [+]preforkmpm: Use prefork MPM * conflicts with eventmpm workermpm universal: Build for multiple architectures workermpm: Use worker MPM * conflicts with eventmpm preforkmpm
This output lists all variants followed by their description.
If a variant depends on or conflicts with other variants, a line with the details on that follows.
Variant lines that have a \+
are enabled and those with -
are disabled.
Any []
are derived from the Portfile
.
While ()
are derived from the variants.conf
.
See Section 6.2.3, “variants.conf” for more information on variants.conf
.
A variant can only be selected when a port is installed. After you have determined what variants a given port has, if any, you may install a port using a variant by specifying its name preceded by a plus sign on the command line, for example
$ sudo port install apache2 +openldap
Multiple variants can be selected by simply listing them one after another separated by a space.
$ sudo port install apache2 +openldap +universal
Use a minus sign to deselect a variant that is on by default.
$ sudo port install apache2 -preforkmpm +workermpm
Note that you will not see any confirmation of successful variant selection and MacPorts will not warn you if you misspelled a variant’s name.
If your installation is successful, but the chosen feature still seems to be missing, check for possible typos.
You can use +port installed+
to verify that the port has been installed with the chosen variant.
This happens because MacPorts will also use the specified variants for any dependencies. For example,
$ sudo port install apache2 +mariadb
is accepted even though apache2
does not have a \+mariadb
variant.
However, it depends on the apr-util
port which does have the \+mariadb
variant and will be installed with it.
MacPorts will remember the variants that were used when installing a port. If you upgrade a port later, the same variants will be used, unless you manually specify different variants.
A Portfile
can specify a default set of variants that will be used when you do not manually override it.
Not all ports specify default variants – if there are no default variants, no variants are chosen by default.
If you wish to disable a variant that has been enabled by default, either by the Portfile
, or by your configuration in variants.conf
, you can negate the variant in question by prefixing the variant name with a minus on the command line:
$ sudo port install apache2 -preformmpm +workermpm