I've been trying to set some environment variables for hours and it does not work grml Here the setting:

I use Debian 6 and there the terminal from the desktop. In this window, I type "su" to login as root. There are two other users: myname and globus. Now I want to set the JAVA_HOME, ANT_HOME and PATH variable for ALL THREE USERS (root, myname, globus). Concerning to this article I edited the /home/myname/.profile and /home/globus/.profile added this:

export JAVA_HOME="/usr"

Now, when I login as globus (open Terminal from desktop and type "su globus") and echo $ANT_HOME, I get "/usr" and not the value above... beside this, I only get a "$" and the beginning of the line and not something like "root@mydebian: /current/path".

This is the content of my .profile:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    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 JAVA_HOME

A user's ~/.profile is read by a login shell. Executing "su user" effectively changes your identity to user by starting a shell as user; you haven't logged in as user. To log in as user, execute "su -l user".

  • "-l" solved my problems :-) Thank you! I didn't get the difference between "login shell" and "other shell"... and how to set this for the root user? When I use "su" only. Or should I use "su -l root"? – strauberry May 16 '11 at 17:41
  • I guess it depends on what task you wish to perform as user and how much of user's identity and environment you want to assume. If you just need to perform some task as a different user, use "su". If you need to perform some task in another user's environment, use "su -l". – garyjohn May 16 '11 at 18:12

That should work:

export JAVA_HOME
export ANT_HOME

You don't need to have that in separate lines, I just like to keep it that way so I can add those to the PATH later, for example:

  • no, unfortunately not :-( – strauberry May 16 '11 at 16:46
  • You'd need to run source /home/myname/.profile to reload the settings immediately. Does that work? – slhck May 16 '11 at 16:49
  • With "-l" it worked... nevertheless I upvoted your answer because of your work, thank you! – strauberry May 16 '11 at 17:42
  • 1
    @strauberry Oh, okay. Maybe your case was too specific :) See here for an explanation on login shell vs. non-login shell: joshstaiger.org/archives/2005/07/bash_profile_vs.html – slhck May 16 '11 at 18:06

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.