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 need to set some variables such as JAVA_HOME and add them to the PATH. Can I somehow define them in .profile, and have them pulled into .bashrc? Or maybe add them to a 3rd file, and have that file referenced in .bashrc and .profile?

share|improve this question

From man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.


Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc and ~/.bashrc, if these files exist and are readable. It will not do this if invoked as sh. The --norc option may be used to inhibit this behavior, and the --rcfile option may be used to force another file to be read, but rshd does not generally invoke the shell with those options or allow them to be specified.

In other words, ~/.profile and ~/.bashrc will normally both be read when you start bash, so you can put it in either.

You can also use the source luke in either file to load the file luke where you would define all your Javan variables. See help . or help source for details.

share|improve this answer

You can do exactly what you mentioned. When you remote ssh into bash terminal the .bash_profile will be sourced and when you create a new xterm the .bashrc will be sourced. Would be better if you put your environment variable information into another file .profile and from both of the .bash_profile and .bashrc source the .profile

. ~/.profile

share|improve this answer
I don't have a .bash_profile. Do I need to create one? When I source the .profile from .bashrc, it wipes out my prompt. – EdgeCase May 24 '13 at 11:10

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.