mardi 15 juillet 2014

Environment variables

First of all, we have different places to setup environment variable. All the following files are applicable to both Ubuntu and Mac OS:
  • ~/.profile:
    use this for variables you want to set in all programs launched from the terminal (note that, unlike on Linux, all shells opened in Terminal.app are login shells).
  • ~/.bashrc:
    this is invoked for shells which are not login shells. Use this for aliases and other things which need to be redefined in subshells, not for environment variables that are inherited.

  • /etc/profile:
    this is loaded before ~/.profile, but is otherwise equivalent. Use it when you want the variable to apply to terminal programs launched by all users on the machine (assuming they use bash).

Ubuntu System

/etc/profile.d/:
All the script in this directory will be automatically executed. For more details, you can check the file /etc/profile


vim /etc/profile

then, you will see:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi



Mac OS X

  • ~/.MacOSX/environment.plist: this is read by login window on login. It applies to all applications, including GUI ones, except those launched by Spotlight in 10.5 (not 10.6). It requires you to logout and login again for changes to take effect. This file is no longer supported as of OS X 10.8. 
  • your user's launchd instance: this applies to all programs launched by the user, GUI and CLI (command line interface). You can apply changes at any time by using the setenv command in launchctl. In theory, you should be able to put setenv commands in ~/.launchd.conf, and launchd would read them automatically when the user logs in, but in practice support for this file was never implemented. Instead, you can use another mechanism to execute a script at login, and have that script call launchctl to set up the launchd environment.
  • /etc/launchd.conf: this is read by launchd when the system starts up and when a user logs in. They affect every single process on the system, because launchd is the root process. To apply changes to the running root launchd you can pipe the commands into sudo launchctl.








a

Aucun commentaire:

Enregistrer un commentaire