On Ubuntu 16.10, I set a system wide environment variable in /etc/environment file. The variable is a string that has a length of thousands of characters (the string is a comma-separated list of small alpha codes). The problem is that the environment variable gets truncated.

Python code to generate the content of /etc/environment file with a variable named X:

fp = open('/etc/environment','w')
fp.write('X="' + ",".join([str(i) for i in range(2000)]) + '"')

Logout shell, login again and show environment variable

echo $X

On my machine, result is:


Someone told me about a 128K limit on environment variables but my variable is relatively small in length. Can anyone explain me why it gets truncated and more important, what can I do to remedy to this situation?

EDIT: output of dpkg -l libpam-modules:

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                           Version                      Architecture                 Description
ii  libpam-modules:amd64                           1.1.8-3.2ubuntu2             amd64                        Pluggable Authentication Modules for PAM
  • Can you confirm that your code successfully placed the entire value in the file?
    – Jeff Schaller
    Jul 6, 2017 at 15:37
  • My file contains only the line X="1,2,3,...,2000"
    – Patrick
    Jul 6, 2017 at 15:53
  • 1
    I would prefer to define system wide env variable in one place instead of in each user's home directory
    – Patrick
    Jul 6, 2017 at 18:28
  • 3
    It looks like pam_env from that package limits the var=value assignments to 1024 bytes each. You can get the source (apt-get source libpam-modules) and modify it, or modify /etc/profile to have your shell read in /etc/environment as if were shell commands. Jul 6, 2017 at 21:32
  • 1
    The second solution seems easier. Can I ask you how to modify /etc/profile? Thanks again Mark.
    – Patrick
    Jul 7, 2017 at 1:35

1 Answer 1


I'm not sure it's exactly what Mark suggested but I updated my /etc/environment file to have now the following syntax:

export X="1,2,..." 

and I added a line in /etc/profile :

source /etc/environment

Don't know if it's the good way but it works.

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.