I defined several environment variables in /etc/environment, but a process (build started by TeamCity) cannot see their values. I don't know what I'm doing wrong here.. this is the content of my /etc/environment file:



ACTIVEMQ_OPTS_MEMORY="-Xms128m -Xmx192m"


The build started by TeamCity uses a Maven runner, and which at some point kicks an Ant build. Since the build was failing, I used Ant to print all environment variables in the system:

<!-- Provides all environment variables as Ant properties prefixed by "env.".
For example, CLASSPATH would be accessible in Ant as ${env.CLASSPATH} -->
<property environment="env"/>

<echo>List of all Environment Variables found in the system:</echo>
        <propertyref prefix="env."/>

Sure enough, the ones I set in /etc/environment don't show up.

The build agent running this is started using Ubuntu's Startup app's, where I configured it to run the command:

sudo -H -u administrator /bin/bash --login -c "~administrator/BuildAgent/bin/agent.sh start"

Could it be that this line runs before /etc/environment are set?

If I do a echo $CATALINA_HOME I see the value properly set, but the build for some reason cannot see it...

NOTE: Although I know it is the wrong way of doing it, I also tried adding export to the declarations inside /etc/environment, without any success. Then I removed it.

NOTE 2: I rebooted the machine after making changes to /etc/environment file, of course.

I'm on 14.04 LTS Server with minimal desktop installed (ubuntu-desktop --no--install-recommends) plus a few extras.

Any help is appreciated, thank you!


Read carefully sudoers man page Command environment section.

try -i option: if sudo's -i option (initial login) is specified, sudoers will initialize the environment regardless of the value of env_reset. The DISPLAY, PATH and TERM variables remain unchanged; HOME, MAIL, SHELL, USER, and LOGNAME are set based on the target user. On AIX (and Linux systems without PAM), the contents of /etc/environment are also included. All other environment variables are removed..

    sudo -u administrator -i "~administrator/BuildAgent/bin/agent.sh start"

If you are using PAM authentication, here is a useful link: Difference between /etc/security/pam_env.conf and /etc/environment + making sudo read pam_env.conf

  • You linked to the manpage for Ubuntu 9.10; that does not have the content you quoted above (or would not, if it still existed), nor does the proper 14.04 sudo manpage. I'm not sure which page you used, but modern versions of the manpage specify that sudo reads /etc/environment only on "Linux systems without PAM." – Curt J. Sampson Feb 27 '18 at 10:04
  • I've confirmed that on a 14.04 system even with the -i or --login system, and a properly configured /etc/pam.d/sudo file, /etc/environment is still not read. It looks like it may be a bug. – Curt J. Sampson Feb 27 '18 at 10:07
  • @CurtJ.Sampson thank you for your comments, I updated my answer up to 14.04 man page. I don't know if it is a bug, because now man page is different. – Lety Feb 27 '18 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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