All Products
Document Center

Enterprise Distributed Application Service:How do I obtain custom environment variables from an application?

Last Updated:May 25, 2023

This topic describes how to obtain custom environment variables from an application.


  • Before you perform high-risk operations, such as modifying the configurations or data of an instance, we recommend that you check the disaster recovery and fault tolerance capabilities of the instance to ensure data security.

  • Before you modify the configurations or data of an instance, such as an Elastic Compute Service (ECS) instance or an ApsaraDB RDS instance, we recommend that you create snapshots or enable the backup feature for the instance. For example, you can enable the log backup feature for an ApsaraDB RDS instance.

  • If you have granted permissions on sensitive information or submitted sensitive information in the Alibaba Cloud Management Console, we recommend that you modify the sensitive information at the earliest opportunity. Sensitive information includes usernames and passwords.

  1. Log on to the application server and run the following command to switch to the admin account:

    su - admin
  2. Edit the ~/.bash_profile file to add the custom environment variables that you want to obtain. Then, save the configurations and exit from the code editor.

    Image - profile file
  3. Run the following command to execute the script:

    source ~/.bash_profile
  4. After you execute the script, call methods such as System.getenv() to obtain the custom environment variables from the application code.


    After the application code is modified, restart the application to make the configurations take effect.