Where to set environment variables

Bob Proulx bob at proulx.com
Wed Oct 20 16:16:46 UTC 2004


Darren Wheatley wrote:
> Can anyone tell me definitively where to put environment settings please?
> I have installed the j2sdk from Sun, but need to alter my PATH to point 
> to it.

In general it is best to avoid the need for setting environment
variables in the user's environment.  This is one of Debian Policy
requirements of official Debian packages that I am sure will be
inherited by Ubuntu too.  Of course you can do anything you want on
your local system.  Local changes are not required to conform to the
official policy.

Instead of making the environment changes to the user profiles it is
much better to make the command find itself.  You can look at the
Blackdown packages to see how they do that.  Generally it is easy to
create a wrapper script that sets the variables that you need.  For
instance in your case it would be easy to have a script in
/usr/local/bin/java such as the following.  I just typed this in so
there may be a typo and of course the paths would need to match what
you installed.

  #!/bin/sh
  export JAVA_HOME="/usr/local/j2re1.5"
  export JDK_HOME="$JAVA_HOME"
  export PATH="$JAVA_HOME/bin:${PATH}"
  exec $(basename $0) "$@"

And if that were linked to javac, javadoc, etc. then all of those
programs would have this behavior and would appear normally on path.
There would be no need to log out and then log back in again for the
changes to take effect since they would be effectively immediately.
Future updates take effect immediately.  It really is a better way of
installing software than requiring the user to log out and then back
in again.  Logging out is akin to rebooting and that is best left to
the lesser operating systems.  Best to make things "just work" for
everyone after installation.

Bob




More information about the ubuntu-users mailing list