What are the main differences between the following? And when should environment variables be put in each of them?
1) /etc/environment
2) $HOME/.bashrc
3) $HOME/.profile
Also if a Desktop environment (KDE or GNOME ) or Window Manager (IceWM, XFCe, etc) is used and an application is started using a shortcut then which of these files is parsed and then the variables used?
[Solved] Difference between /etc/environment, .bashrc and .profile
Re: Difference between /etc/environment, .bashrc and .profile
/etc/ configuration files affect the whole system. Configuration files in your home directory affect only you as a user, no other users and not the root.
You don't need to edit them or add to them, unless you know what you're doing.
You don't need to edit them or add to them, unless you know what you're doing.
- wizard10000
- Global Moderator
- Posts: 1144
- Joined: 2019-04-16 23:15
- Location: southeastern us
- Has thanked: 120 times
- Been thanked: 198 times
Re: Difference between /etc/environment, .bashrc and .profile
All of those files are parsed. As @Bloom mentioned /etc/environment is a systemwide config. ~/.profile is sourced once when you first log on to the machine, ~/.bashrc is sourced any time bash is called - like when you run a script or open a terminal window.
Hope this helps-
Hope this helps-
we see things not as they are, but as we are.
-- anais nin
-- anais nin
Re: Difference between /etc/environment, .bashrc and .profile
Thanks that does help. So if I want a environment variable to be defined, like those observed when we give the env command in the terminal, for all the users then those variables have to be put in /etc/environment file. However if I want a particular variable to be defined only for a particular user, then should that be put in .profile file or .bashrc file?
For example there is an application that is run by User A. The application is not started from a terminal shell, i.e. bash shell. Rather from a shortcut. This application looks for a particular environment variable say MYDIR. And I want this variable to be different for each user. So should I put this in .profile?
For example there is an application that is run by User A. The application is not started from a terminal shell, i.e. bash shell. Rather from a shortcut. This application looks for a particular environment variable say MYDIR. And I want this variable to be different for each user. So should I put this in .profile?
- wizard10000
- Global Moderator
- Posts: 1144
- Joined: 2019-04-16 23:15
- Location: southeastern us
- Has thanked: 120 times
- Been thanked: 198 times
Re: Difference between /etc/environment, .bashrc and .profile
I'd stick it in .profile because the variable only needs to be set once. It's not gonna hurt anything to put it in .bashrc but it seems a little inefficient to reset the same variable every time bash is called.
we see things not as they are, but as we are.
-- anais nin
-- anais nin
- wizard10000
- Global Moderator
- Posts: 1144
- Joined: 2019-04-16 23:15
- Location: southeastern us
- Has thanked: 120 times
- Been thanked: 198 times
Re: Difference between /etc/environment, .bashrc and .profile
I think you just answered your own questionDebianFox wrote: 2024-08-29 13:10But the application is not launched via shell. A terminal/shell is not opened first.
we see things not as they are, but as we are.
-- anais nin
-- anais nin
- wizard10000
- Global Moderator
- Posts: 1144
- Joined: 2019-04-16 23:15
- Location: southeastern us
- Has thanked: 120 times
- Been thanked: 198 times
Re: Difference between /etc/environment, .bashrc and .profile
Yep. No reason to redefine those variables every time you open a terminal window
we see things not as they are, but as we are.
-- anais nin
-- anais nin