|
| 1 | +--- |
| 2 | +description: DSC.PackageManagement/Apt resource reference documentation |
| 3 | +ms.date: 06/30/2025 |
| 4 | +ms.topic: reference |
| 5 | +title: DSC.PackageManagement/Apt |
| 6 | +--- |
| 7 | + |
| 8 | +# DSC.PackageManagement/Apt |
| 9 | + |
| 10 | +## Synopsis |
| 11 | + |
| 12 | +Manage packages with the advanced package tool (APT) on Linux systems. |
| 13 | + |
| 14 | +> [!IMPORTANT] |
| 15 | +> The `DSC.PackageManagement/Apt` resource is a proof-of-concept example |
| 16 | +> for use with DSC. Don't use it in production. |
| 17 | +
|
| 18 | +## Metadata |
| 19 | + |
| 20 | +```yaml |
| 21 | +Version : 0.1.0 |
| 22 | +Kind : resource |
| 23 | +Tags : [Linux, apt, PackageManagement] |
| 24 | +Author : Microsoft |
| 25 | +``` |
| 26 | +
|
| 27 | +## Instance definition syntax |
| 28 | +
|
| 29 | +```yaml |
| 30 | +resources: |
| 31 | + - name: <instance name> |
| 32 | + type: DSC.PackageManagement/Apt |
| 33 | + properties: |
| 34 | + # Required properties |
| 35 | + packageName: string |
| 36 | + # Instance properties |
| 37 | + _exist: boolean |
| 38 | + version: string |
| 39 | +``` |
| 40 | +
|
| 41 | +## Description |
| 42 | +
|
| 43 | +The `DSC.PackageManagement/Apt` resource enables you to idempotently manage packages with the Advanced Package Tool (APT) on |
| 44 | +Linux systems. The resource can: |
| 45 | + |
| 46 | +- Install packages |
| 47 | +- Uninstall packages |
| 48 | +- Check if a package is installed |
| 49 | +- Verify the version of an installed package |
| 50 | + |
| 51 | +> [!NOTE] |
| 52 | +> This resource only works on Linux systems that use the APT package manager, such as Ubuntu and Debian. |
| 53 | + |
| 54 | +## Requirements |
| 55 | + |
| 56 | +- A Linux system with APT installed |
| 57 | +- Administrative privileges (root or sudo access) to install and remove packages |
| 58 | + |
| 59 | +## Capabilities |
| 60 | + |
| 61 | +The resource has the following capabilities: |
| 62 | + |
| 63 | +- `get` - You can use the resource to retrieve the actual state of an instance. |
| 64 | +- `set` - You can use the resource to enforce the desired state for an instance. |
| 65 | +- `export` - You can use the resource to export the current state of the system. |
| 66 | + |
| 67 | +This resource uses the synthetic test functionality of DSC to determine whether an instance is in |
| 68 | +the desired state. For more information about resource capabilities, see |
| 69 | +[DSC resource capabilities][00]. |
| 70 | + |
| 71 | +## Examples |
| 72 | + |
| 73 | +1. [Manage packages with APT](./examples/manage-packages-with-apt.md) - Shows how to install, uninstall, |
| 74 | + and check packages with the `DSC.PackageManagement/Apt` resource. |
| 75 | + |
| 76 | +## Properties |
| 77 | + |
| 78 | +The following list describes the properties for the resource. |
| 79 | + |
| 80 | +- **Required properties:** <a id="required-properties"></a> The following properties are always |
| 81 | + required when defining an instance of the resource. An instance that doesn't define each of these |
| 82 | + properties is invalid. For more information, see the "Required resource properties" section in |
| 83 | + [DSC resource properties][01] |
| 84 | + |
| 85 | + - [packageName](#packagename) - The name of the package to query or install. |
| 86 | + |
| 87 | +- **Key properties:** <a id="key-properties"></a> The following properties uniquely identify an |
| 88 | + instance. If two instances of a resource have the same values for their key properties, the |
| 89 | + instances are conflicting. For more information about key properties, see the "Key resource |
| 90 | + properties" section in [DSC resource properties][02]. |
| 91 | + |
| 92 | + - [packageName](#packagename) (required) - The name of the package to query or install. |
| 93 | + |
| 94 | +- **Instance properties:** <a id="instance-properties"></a> The following properties are optional. |
| 95 | + They define the desired state for an instance of the resource. |
| 96 | + |
| 97 | + - [_exist](#_exist) - Defines whether the package should exist. |
| 98 | + - [version](#version) - The version of the package to install. |
| 99 | + |
| 100 | +- **Read-only properties:** <a id="read-only-properties"></a> The resource returns the following |
| 101 | + properties, but they aren't configurable. For more information about read-only properties, see |
| 102 | + the "Read-only resource properties" section in [DSC resource properties][03]. |
| 103 | + |
| 104 | + - [source](#source) - Indicates the source of the package. |
| 105 | + |
| 106 | +### packageName |
| 107 | + |
| 108 | +<details><summary>Expand for <code>packageName</code> property metadata</summary> |
| 109 | + |
| 110 | +```yaml |
| 111 | +Type : string |
| 112 | +IsRequired : true |
| 113 | +IsKey : true |
| 114 | +IsReadOnly : false |
| 115 | +IsWriteOnly : false |
| 116 | +``` |
| 117 | + |
| 118 | +</details> |
| 119 | + |
| 120 | +Defines the name of the package to query or install. This property is required and serves as the key for uniquely |
| 121 | +identifying the package. |
| 122 | + |
| 123 | +### _exist |
| 124 | + |
| 125 | +<details><summary>Expand for <code>_exist</code> property metadata</summary> |
| 126 | + |
| 127 | +```yaml |
| 128 | +Type : boolean |
| 129 | +IsRequired : false |
| 130 | +IsKey : false |
| 131 | +IsReadOnly : false |
| 132 | +IsWriteOnly : false |
| 133 | +DefaultValue : true |
| 134 | +``` |
| 135 | + |
| 136 | +</details> |
| 137 | + |
| 138 | +The `_exist` canonical resource property determines whether a package should exist. When the |
| 139 | +value for `_exist` is `true`, the resource installs the package if it doesn't exist. When |
| 140 | +the value for `_exist` is `false`, the resource removes or uninstalls the package if it does exist. |
| 141 | +The default value for this property when not specified for an instance is `true`. |
| 142 | + |
| 143 | +### version |
| 144 | + |
| 145 | +<details><summary>Expand for <code>version</code> property metadata</summary> |
| 146 | + |
| 147 | +```yaml |
| 148 | +Type : string |
| 149 | +IsRequired : false |
| 150 | +IsKey : false |
| 151 | +IsReadOnly : false |
| 152 | +IsWriteOnly : false |
| 153 | +``` |
| 154 | + |
| 155 | +</details> |
| 156 | + |
| 157 | +Defines the version of the package to install. If not specified, the latest available version will be installed. |
| 158 | + |
| 159 | +### source |
| 160 | + |
| 161 | +<details><summary>Expand for <code>source</code> property metadata</summary> |
| 162 | + |
| 163 | +```yaml |
| 164 | +Type : string |
| 165 | +IsRequired : false |
| 166 | +IsKey : false |
| 167 | +IsReadOnly : true |
| 168 | +IsWriteOnly : false |
| 169 | +``` |
| 170 | + |
| 171 | +</details> |
| 172 | + |
| 173 | +Indicates the source of the package. This is a read-only property returned by the resource after a `get` operation. |
| 174 | + |
| 175 | +## Exit codes |
| 176 | + |
| 177 | +The resource returns the following exit codes from operations: |
| 178 | + |
| 179 | +- [0](#exit-code-0) - Success |
| 180 | +- [1](#exit-code-1) - Invalid parameter |
| 181 | + |
| 182 | +### Exit code 0 |
| 183 | + |
| 184 | +Indicates the resource operation completed without errors. |
| 185 | + |
| 186 | +### Exit code 1 |
| 187 | + |
| 188 | +Indicates the resource operation failed due to an invalid parameter. When the resource returns this |
| 189 | +exit code, it also emits an error message with details about the invalid parameter. |
| 190 | + |
| 191 | +## See also |
| 192 | + |
| 193 | +- [For more information about APT](https://wiki.debian.org/Apt) |
| 194 | + |
| 195 | +<!-- Link definitions --> |
| 196 | +[00]: ../../../../../concepts/resources/capabilities.md |
| 197 | +[01]: ../../../../../concepts/resources/properties.md#required-resource-properties |
| 198 | +[02]: ../../../../../concepts/resources/properties.md#key-resource-properties |
| 199 | +[03]: ../../../../../concepts/resources/properties.md#read-only-resource-properties |
0 commit comments