How to set environment variables in Linux?

There are multiple ways to set environment variables in Linux, one common method is as follows:

  1. Open the terminal and type the following command to edit the environment variable configuration file:
sudo nano /etc/profile
  1. Add the desired environment variables at the end of the file, for example:
export MY_VAR="value"
  1. Save and close the file, then enter the following command to apply the changes:
source /etc/profile
  1. You can verify if the environment variables are successfully set by entering the following command:
echo $MY_VAR

This allows you to set environment variables in Linux. Please note that the environment variables set by the above method will take effect after the current user logs in. If you need them to take effect globally, you can add the environment variables to the /etc/environment file.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds