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?

asked Feb 26, 2017 at 17:11

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.

tlhIngan
3,3725 gold badges21 silver badges33 bronze badges
answered Feb 26, 2017 at 22:43
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. Commented Feb 27, 2017 at 18:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.