8

I need to set a system wide environment variable on Raspbian jessie. System wide means in this case not only for logged in users but also for all services (in detail for lirc and irexec service).

I already tried the following ways:

Adding an entry to /env/environment: works well for logged in users but not for irexec.

I am getting the same result when creating a file with an export command in /etc/profile.d/test.sh.

What is the correct way to set an environment variables for all services and logged-in users?

1 Answer 1

6

A common way is to put your environment variables in /etc/profile. For example (I'm using vim, feel free to use a different text editor):

sudo vim /etc/profile
export THREADCOUNT=5 (put this at the end of your file)
:wq (saves the file)

Access your variable once you log out or open a new shell:

printenv THREADCOUNT // returns 5

or

echo $THREADCOUNT // returns 5

Things to note: You have to be root to edit the file, and environment variables are typically always uppercased.

1
  • 2
    The script /etc/profile is the one that executes the scripts in /etc/profile.d/ which I mentioned in my question that placing an export in there does not have an effect on the lirc service.
    – Robert
    Commented Feb 27, 2017 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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