Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following line my /etc/environment file:


I run this and get:

$ set|grep BROKER_URL

Then, I run:

$ sudo bash
# set|grep BROKER_URL

This is supposed to be a system wide environment variable. Why doesn't it show up in my sudo shell?

share|improve this question
up vote 5 down vote accepted

/etc/environment is a file used by PAM, meaning it is processed by a log in, which sudo bash does not do, and (from man sudoers):

Command environment

Since environment variables can influence program behavior, sudoers provides a means to restrict which variables from the user's environment are inherited by the command to be run. There are two distinct ways sudoers can deal with environment variables.

By default, the env_reset option is enabled. This causes commands to be executed with a new, minimal environment. On AIX (and Linux systems without PAM), the environment is initialized with the contents of the /etc/environment file.

Note that most GNU/linux systems do use PAM. You could try to get around this by using sudo -i, to use a login shell. However, this likely will still not work as "login shell" refers to how bash invokes itself, which does not include sourcing /etc/environment, and you are not actually logging in via PAM.

Your best bet is probably to configure sudo to do what you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.