3

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
strauberry
  • 647
  • 3
  • 10
  • 25

2 Answers2

1

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
slhck
  • 223,558
  • 70
  • 607
  • 592
  • 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: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html – slhck May 16 '11 at 18:06
1

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

garyjohn
  • 34,610
  • 8
  • 97
  • 89
  • "-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