Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to set a couple of environment variables (at boot time) on an Ubuntu machine (10.04), but I want to create their value via a script, much like:

export THE_ENV_VAR=$(script_to_execute_and_use_stdout_from)
  • The reason I want to do this is that the commands used to set the environment variables take long time to execute (10s or so), so that's why I only want to do it once after boot. Anyway, currently I solved this by caching the result of the command at boot time, so that subsequent calls will go fast, thus not using env. variables at all.

I've tried setting in /etc/environment, but that only copies rhs verbatim

I've tried executing a script in /etc/init.d/ at startup, but that does not seem to work.


share|improve this question

Put that in ~/.bash_profile or ~/.bashrc

gedit ~/.bashrc

Use .bash_profile if you need to use those variable with non-interactive shells (scripts) and ~/.bashrc if you are setting your variables in a shell.

If that does not work, we need more details, in particular what variables are you setting and for what purpose ?

share|improve this answer
This is not at boot time... – user877329 Oct 22 '14 at 9:53

Put your commands into /etc/rc.local. Make sure to read the comments at the head.

share|improve this answer
Ok, tried that too, but it doesn't seem to work either, when I login after rebooting the variables don't exist :( – Robert Oct 13 '11 at 4:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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