Skip to content

Q&A · Answered

How to set environment variables permanently

asked 9 months, 2 weeks ago 893 views 1 answer
19

How do I set environment variables that persist after reboot?

1 Answer

One accepted
19

Accepted answer

Not confirmed since it was written, 9 months, 2 weeks ago
# For current user - add to ~/.bashrc
echo 'export MY_VAR="value"' >> ~/.bashrc
source ~/.bashrc

# For all users - add to /etc/environment
sudo nano /etc/environment
MY_VAR="value"

# For services - use systemd override
sudo systemctl edit myservice
[Service]
Environment="MY_VAR=value"

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.