I was installing an application and had trouble with understanding why the installation guide told to add an export command to the one of startup files. I did not see when it is executed. That was the line:

export WORKON_HOME=$HOME/.virtualenvs

I executed some code in terminal and figured out that the export command did not work. Why?

root@localhost:/home/gameboy# echo export ADAM=Boss>>/home/pythontest/.profile
root@localhost:/home/gameboy# tail /home/pythontest/.profile
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
export ADAM=Boss
root@localhost:/home/gameboy# su pythontest
pythontest@localhost:/home/gameboy$ echo $ADAM


~/.profile may be run at the launch of a login Bash shell.

First the system executes the system-wide /etc/profile, then the first of these files which exists and is readable:


Your problem is that you're changing user via su pythontest. You must ensure that the spawned shell is a login shell by adding the -l flag:

su -l pythontest
| improve this answer | |

You either do export ADAM=Boss afterwards for immediate change or . ~/.profile to force the shell to re-read the .profile file.

| improve this answer | |
  • So what for are .profile files? I can put my export command to any file and execute it whenever I want. I thought that .profile file is run by a system. – trzczy Feb 28 '17 at 15:06
  • You should read the manual page for your shell. – schaiba Feb 28 '17 at 15:10
  • In man there is a topic "Invoked as an interactive login shell, or with --login". Is the problem of being an interactive shell? When I use su command bash is not invoked by interactive login shell? – trzczy Feb 28 '17 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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