All Products
Search
Document Center

Alibaba Cloud SDK:Configure environment variables in Linux, macOS, and Windows

Last Updated:Dec 22, 2025

Environment variables are operating system-specific system-level parameters whose names and values are specific. Environment variables provide runtime environment settings for applications running on an operating system. This topic describes how to configure an AccessKey pair in environment variables of Linux, macOS, and Windows.

Using an Alibaba Cloud account, which has access permissions for all resources, poses a high security threat. We strongly recommend that you create and use a Resource Access Management (RAM) user for resource access or daily operations and maintenance (O&M). Before you call API operations, assign only the necessary permissions to the RAM user. For more information about how to obtain the AccessKey of a RAM user, see Create an AccessKey and Manage permissions for a RAM user. When you call API operations using an AccessKey, do not hardcode the plaintext AccessKey in your code. Instead, you can configure environment variables or use other secure methods that do not involve plaintext AccessKeys.

Configure an AccessKey pair in the environment variables of Linux and macOS

This section uses the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET as an example. You can replace the variable names as needed, such as OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.

You can configure environment variables using the export command:

Important

Environment variables that are configured using the export command are temporary and valid only for the current session. To ensure long-term retention (LTR), add the export command to the startup configuration file of the operating system.

  • Configure the AccessKey ID and press Enter.

    # Replace yourAccessKeyID with your AccessKey ID.
    export ALIBABA_CLOUD_ACCESS_KEY_ID=yourAccessKeyID
  • Configure the AccessKey secret and press Enter.

    # Replace yourAccessKeySecret with your AccessKey secret.
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=yourAccessKeySecret
  • Check whether the configuration is successful.

    Run the echo $ALIBABA_CLOUD_ACCESS_KEY_ID command. The configuration is successful if the correct AccessKey ID is returned.

Configure an AccessKey pair in the environment variables of Windows

This section uses the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET as an example. You can replace the variable names as needed, such as OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.

Use GUI

  • Procedure

    If you want to use GUI to configure environment variables in Windows 10, perform the following steps:

    On the Windows desktop, right-click This PC and select Properties. On the page that appears, click Advanced system settings. In the System Properties dialog box, click Environment Variables on the Advanced tab. In the Environment Variables dialog box, click New in the User variables or System variables section. Then, configure the variables described in the following table.

    Variable

    Example

    AccessKey ID

    • Variable name: ALIBABA_CLOUD_ACCESS_KEY_ID

    • Variable value: LTAI****************

    AccessKey Secret

    • Variable name: ALIBABA_CLOUD_ACCESS_KEY_SECRET

    • Variable value: yourAccessKeySecret

  • Check whether the configuration is successful.

    Click Start (or use the keyboard shortcut Win+R ), enter cmd in the Run dialog box, and then click OK (or press Enter) to open the command prompt. Run the echo %ALIBABA_CLOUD_ACCESS_KEY_ID% and echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET% commands. The configuration is successful if the correct AccessKeys are returned.

Use CMD

  • Procedure

    Open a Command Prompt window as an administrator and run the following commands to add environment variables in the operating system:

    setx ALIBABA_CLOUD_ACCESS_KEY_ID yourAccessKeyID /M
    setx ALIBABA_CLOUD_ACCESS_KEY_SECRET XXXXXXX /M

    The /M parameter indicates a system variable. If you omit this parameter, a user variable is set.

  • Check whether the configuration is successful.

    Click Start (or use the keyboard shortcut Win+R ), enter cmd in the Run dialog box, and then click OK (or press Enter) to open the command prompt. Run the echo %ALIBABA_CLOUD_ACCESS_KEY_ID% and echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET% commands. The configuration is successful if the correct AccessKeys are returned.

Use Windows PowerShell

In PowerShell, configure new environment variables. The environment variables apply to all new sessions.

[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'yourAccessKeyID', [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'XXXXXXX', [System.EnvironmentVariableTarget]::User)

Configure environment variables for all users. You must run the following commands as an administrator.

[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'yourAccessKeyID', [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'XXXXXXX', [System.EnvironmentVariableTarget]::Machine)

Set temporary environment variables for the current session:

$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "yourAccessKeyID"
$env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "XXXXXXX"

In PowerShell, run the Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_ID and Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_SECRET commands. A successful configuration returns the correct AccessKeys.

Important

After you configure the environment variables, you may need to restart your development tools, such as an Integrated Development Environment (IDE), or related services to ensure the new settings take effect.