anchor.diff:  owner: CAPI
   ---
   
  -
  -
  -Environment variables are the means by which the Cloud Foundry (CF) runtime
  -communicates with a deployed app about its environment.
  -This page describes the environment variables that the runtime and buildpacks
  -set for app.
  -
  -For information about setting your own app-specific environment
  -variables, see the [Environment Variable](./manifest.html#env-block) section of the _Deploying with App Manifests_ topic.
  -
  -## <a id='view-env'></a>View Environment Variables ##
  -
  -Install the Cloud Foundry Command Line Interface (cf CLI), and use the [cf env](http://cli.cloudfoundry.org/en-US/cf/env.html) command to view the Cloud
  -Foundry environment variables for your app.
  -The `cf env` command displays the following environment variables:
  +This page describes the environment variables that the Cloud Foundry (CF) runtime and buildpacks set for a deployed app.
  +
  +
  +## <a id='overview'></a> Overview
  +
  +Environment variables are the means by which the CF runtime communicates with a deployed app about its environment.
  +
  +For information about setting your own app-specific environment variables, see the [Environment Variable](./manifest.html#env-block) section of the _Deploying with App Manifests_ topic.
  +
  +
  +## <a id='view-env'></a> View Environment Variables
  +
  +Install the Cloud Foundry Command Line Interface (cf CLI), and use the `cf env` command to view the CF environment variables for your app. The `cf env` command displays the following environment variables:
   
   * The `VCAP_APPLICATION` and `VCAP_SERVICES` variables provided in the container environment
  -* The user-provided variables set using the [cf set-env](http://cli.cloudfoundry.org/en-US/cf/set-env.html) command
  +
  +* The user-provided variables set using the `cf set-env` command
  +
  +For more information about the `cf env` command, see [env](http://cli.cloudfoundry.org/en-US/cf/env.html) in the cf CLI documentation. For more information about the `cf set-env` command, see [set-env](http://cli.cloudfoundry.org/en-US/cf/set-env.html) in the cf CLI documentation.
  +
  +The following example demonstrates the environment variables `cf env` displays:
   
   <pre class="terminal">
   $ cf env my-app
  
positive.code: MY_ENV_VARIABLE: 100
  </pre>
  
  ## <a id='app-system-env'></a>App-Specific System Variables ##
  
  The subsections that follow describe the environment variables that Cloud
  Foundry makes available to your app container.
  Some of these variables are the same across instances of a single app,
  and some vary from instance to instance.
  
  You can access environment variables programmatically, including variables
  defined by the buildpack.
  For more information, refer to the buildpack documentation for
  [Java](../../buildpacks/java/java-tips.html#env-var),
  [Node.js](../../buildpacks/node/node-tips.html#env-var), and
  [Ruby](../../buildpacks/ruby/ruby-tips.html#env-var).
  
  <table border="1" class="nice">
    <tr>
      <th>Env Var</th>
      <th>Running</th>
      <th>Staging</th>
      <th>Task</th>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_ADDR</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_GUID</code></td>
      <td>x</td>
      <td></td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_INDEX</code></td>
      <td>x</td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_INTERNAL_IP</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_IP</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_PORT</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>CF_INSTANCE_PORTS</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>CF_STACK</code></td>
      <td></td>
      <td>x</td>
      <td></td>
    </tr>
    <tr>
      <td><code>DATABASE_URL</code></td>
      <td>x</td>
      <td></td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>HOME</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>INSTANCE_GUID</code></td>
      <td>x</td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td><code>INSTANCE_INDEX</code></td>
      <td>x</td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td><code>LANG</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>MEMORY_LIMIT</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>PATH</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>PORT</code></td>
      <td>x</td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td><code>PWD</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>TMPDIR</code></td>
      <td>x</td>
      <td></td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>USER</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>VCAP_APP_HOST</code></td>
      <td>x</td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td><code>VCAP_APP_PORT</code></td>
      <td>x</td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td><code>VCAP_APPLICATION</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
    <tr>
      <td><code>VCAP_SERVICES</code></td>
      <td>x</td>
      <td>x</td>
      <td>x</td>
    </tr>
  </table>
  
  ### <a id='CF-INSTANCE-ADDR'></a>CF\_INSTANCE\_ADDR ###
  The [CF\_INSTANCE\_IP](#CF-INSTANCE-IP) and
  [CF\_INSTANCE\_PORT](#CF-INSTANCE-PORT) of the app instance in the format
  `IP:PORT`.
  
  Example: `CF_INSTANCE_ADDR=1.2.3.4:5678`
  
  ### <a id='CF-INSTANCE-GUID'></a>CF\_INSTANCE\_GUID ###
  The UUID of the particular instance of the app.
  
  Example: `CF_INSTANCE_GUID=41653aa4-3a3a-486a-4431-ef258b39f042`
  
  ### <a id='CF-INSTANCE-INDEX'></a>CF\_INSTANCE\_INDEX ###
  The index number of the app instance.
  
  Example: `CF_INSTANCE_INDEX=0`
  
  ### <a id='CF-INSTANCE-IP'></a>CF\_INSTANCE\_IP ###
  The external IP address of the host running the app instance.
  
  Example: `CF_INSTANCE_IP=1.2.3.4`
  
  ### <a id='CF-INSTANCE-INTERNAL-IP'></a>CF\_INSTANCE\_INTERNAL_IP ###
  The internal IP address of the container running the app instance.
  
  Example: `CF_INSTANCE_INTERNAL_IP=5.6.7.8`
  
  ### <a id='CF-INSTANCE-PORT'></a>CF\_INSTANCE\_PORT ###
  
  The external, or *host-side*, port corresponding to the internal, or *container-side*, port with value [PORT](#PORT).
  This value is generally different from the
  [PORT](#PORT) of the app instance.
  
  Example: `CF_INSTANCE_PORT=61045`
  
  ### <a id='CF-INSTANCE-PORTS'></a>CF\_INSTANCE\_PORTS ###
  
  The list of mappings between internal, or *container-side*, and external, or *host-side*, ports allocated to the instance's container.
  Not all of the internal ports are necessarily available for the app to
  bind to, as some of them may be used by system-provided services that also run
  inside the container. These internal and external values may differ.
  
  Example: `CF_INSTANCE_PORTS=[{external:61045,internal:8080},{external:61046,internal:2222}]`
  
  ### <a id='DATABASE-URL'></a>DATABASE\_URL ###
  
  For apps bound to certain services that use a database, CF creates a `DATABASE_URL` environment variable based on the [VCAP_SERVICES](#VCAP-SERVICES) environment variable at runtime.
  
  CF uses the structure of the `VCAP_SERVICES` environment variable to populate `DATABASE_URL`.
  CF recognizes any service containing a JSON object with the following form as a candidate for `DATABASE_URL` and uses the first candidate it finds.
  
      {
        "some-service": [
  
negative.code: ~~~
  
  
  ## <a id='evgroups'></a> Environment Variable Groups
  
  Environment variable groups are system-wide variables that enable operators to apply a group of environment variables to all running apps and all staging apps separately.
  
  An environment variable group consists of a single hash of name-value pairs that are later inserted into an app container at runtime or at staging. These values can contain information such as HTTP proxy information. The values for variables set in an environment variable group are case-sensitive.
  
  When creating environment variable groups, consider:
  
  * Only the Cloud Foundry operator can set the hash value for each group.
  
  * All authenticated users can get the environment variables assigned to their app.
  
  * All variable changes take effect after the operator restarts or restages the apps.
  
  * Any user-defined variable takes precedence over environment variables provided by these groups.
  
  The table below lists the commands for environment variable groups.
  
  | CLI Command | Description |
  | ----------- | ----------- |
  | `running-environment-variable-group` or `revg` | Retrieves the contents of the running environment variable group. |
  | `staging-environment-variable-group` or `sevg` | Retrieves the contents of the staging environment variable group. |
  | `set-staging-environment-variable-group` or `ssevg` | Passes parameters as JSON to create a staging environment variable group. |
  | `set-running-environment-variable-group` or `srevg` | Passes parameters as JSON to create a running environment variable group. |
  
  The following examples demonstrate how to retrieve the environment variables:
  
  