Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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"
ANT_HOME="/lib/apache-ant-1.8.2"

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"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

JAVA_HOME=/usr/bin;
export JAVA_HOME
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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".

share|improve this answer
    
"-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
add comment

That should work:

JAVA_HOME=/usr;
export JAVA_HOME
ANT_HOME=/lib/apache-ant-1.8.2;
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:

GRAILS_HOME=/Users/werner/Library/grails;
export GRAILS_HOME
export PATH=$GRAILS_HOME/bin:$PATH
share|improve this answer
    
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
1  
Thank you for that link! –  strauberry May 17 '11 at 8:48
add comment

Your Answer

 
discard

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.