set environment or enviroment variable linux

https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/


  1. /etc/environment This is the best place for variables that are system-wide. This includes extending variable PATH with paths from /usr/local or for JAVA_HOME Do not use export here or duplicate definitions. 
  2. /etc/xprofile Very little known but very useful for everyone who uses X window system. This is executed for every user that logs into X. It is very good choice for values that are valid for every user like /usr/local. Documentation.
  3. /etc/profile and /etc/profile.d/* This is a good choice for non X systems but bad for X ones. Those files are read only by shells.
  4. /etc/<shell>.<shell>rc. This is not a good choice because it is single shell specific. Also forget about X.
  5. ~/.xprofile The same as 2. This is executed when the user logs into X. The variables defined here are visible to every X application. A very good place for extending PATH with values such as ~/bin or ~/gocode/bin or defining user specific GOPATH. Your graphical text editor or IDE started by shortcut will see those values. Documentation.
  6. ~/.profile It will be visible only for programs started from terminal or terminal emulator. It is a good choice for systems where you do not use X window system.
  7. ~/.<shell>rc. This is not a good choice because it is single shell specific.

/bin/bash
       The bash executable
/etc/profile
       The systemwide initialization file, executed for login shells
~/.bash_profile
       The personal initialization file, executed for login shells
~/.bashrc
       The individual per-interactive-shell startup file
~/.bash_logout
       The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
       Individual readline initialization file
 
If you have ever put something in a file like .bashrc and had it not work, or are confused by why there are so many different files — .bashrc, .bash_profile, .bash_login, .profile etc. — and what they do, this is for you.
The issue is that Bash sources from a different file based on what kind of shell it thinks it is in. For an “interactive non-login shell”, it reads .bashrc, but for an “interactive login shell” it reads from the first of .bash_profile, .bash_login and .profile (only). There is no sane reason why this should be so; it’s just historical. Follows in more detail.
For Bash, they work as follows. Read down the appropriate column. Executes A, then B, then C, etc. The B1, B2, B3 means it executes only the first of those files found.



 
 


No comments:

Post a Comment