Environment variables - where are they stored by linux, how do I change them and is it safe to do so?

59,474

Solution 1

The Global environment variables of your system are stored in /etc/environment.
Any changes here will get reflected throughout the system and will affect all users of the system. Also, you need a Reboot, for any changes made here to take effect.

User level Environment variables are mostly stored in .bashrc and .profile files in your Home folder. Changes here only affect that particular user. Just close and open the terminal for configuration changes to take place.

Edit : If you don't want to Reboot or restart your terminal, you can make use of the source command.
Eg. source /etc/environment or source .bashrc

Solution 2

What you need is local temporal changes. You are not going to need them tomorrow, when you are doing something else, it may break the thing you do tomorrow. However you could save it as a build-script/makefile for use tomorrow.

export VARIABLE=value
export VARIABLE2=another_value
gcc …

or

VARIABLE=value VARIABLE2=another_value gcc …

note: If using make, the first example wont work. Make starts a new shell (sh) for each line.

Solution 3

You should place your environment variables on a per-user basis in ~/.pam_environment

Create the file if it doesn't exist. See here

Share:
59,474

Related videos on Youtube

mathematician1975
Author by

mathematician1975

Updated on September 18, 2022

Comments

  • mathematician1975
    mathematician1975 over 1 year

    I am trying to configure a build from source an old version of gcc on my dev machine. The documentation highlight several environment variables that need to be changed in order to do this. I was wondering how to do this and also where linux stores them and if a system restart is required for any changes to be registered??

  • Sergey Poskachey
    Sergey Poskachey almost 12 years
    You don't need a reboot. You can use source command to load the variables after a change. ex: source /etc/environment or source .bashrc
  • ctrl-alt-delor
    ctrl-alt-delor almost 12 years
    For what you are trying to do changing .profile in not the right thing to do. .bashrc should not be used as it can under some situations lead problems. And /etc/environment is way out (don't change the system to do one job).
  • polendina
    polendina about 3 years
    if i used source ~/.bashrc it does word , without having to restart the terminal emulator , but for some reason on my system i.e., elemenetary os hera , if i updated the environment on the ~/.bashrc file using one terminal emulator , the i'll have to restart any other gui-based terminal emulator i.e., pantheon&xfce terminal emulators-even if i sourced the ~/.bashrc file- so that the change can take effect