2013年5月9日 星期四

System-wide environment variables in Ubuntu

要怎麼新增一個 system-wide global environment 可參考以下這篇

  • /etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.
Not recommended:
  • /etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more than invoke the /etc/bash.bashrc file.
  • /etc/bash.bashrc - This is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.

如果加在 /etc/bash.bashrc 內, sudo xxxx, 的時候不會發揮作用, 因為沒有真的 login
有些時候希望sudoer 能繼承自己的 local variable, 可以使用以下方式, 把 env_reset 換成 env_keep

# This file MUST be edited with the 'visudo' command as root.
# See the man page for details on how to write a sudoers file.

#Defaults       env_reset
Defaults        env_keep+="PERL5LIB"