Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an environment variable to set the temporary directory on debian based systems?

I have a java applet that uses that environement variable and it's getting confused when launching two instances of the same applet.

share|improve this question
up vote 7 down vote accepted

I am unsure if the java applet will actually look at the environment variables before it starts, but what you can do it edit /etc/profile and add the following lines:

if [[ -O /home/$USER/tmp && -d /home/$USER/tmp ]]; then
        # You may wish to remove this line, it is there in case
        # a user has put a file 'tmp' in there directory or a
        rm -rf /home/$USER/tmp 2> /dev/null
        mkdir -p /home/$USER/tmp
        TMPDIR=$(mktemp -d /home/$USER/tmp/XXXX)



To make it a true tmp directory (as in the files go away when the session is ended, you'll want to edit the user's .bash_logout as well as the skeleton .bash_logout (/etc/skel/.bash_logout) to include the following:

if [ -O $TMPDIR && -d $TMPDIR ]; then
        rm -rf $TMPDIR/*

The logout portion is dangerous is the variable doesn't get set and your logged in as root! I wouldn't add this to the root account or anyone that is a member of the wheel group! Proceed at your own caution.

share|improve this answer
I wouldn't put the cleanup into .bash_logout at all - what happens if they open up two sessions and log out of one? Use tmpwatch. :) – MikeyB Oct 10 '09 at 4:19
That is a much better cleanup solution, thanks for adding that. :) – TrueDuality Oct 16 '09 at 12:34

The file you are looking for is:


You have to set the TEMP variable like:

share|improve this answer
And even export TEMP=/home/user/tmp – Fedir Jun 27 '14 at 15:06
@Fedir that is in the shell, yes. – cstamas Jul 2 '14 at 19:33

If you want /home/user/tmp to be cleaned on reboot, I suggest you add an @reboot job to the user's personal crontab.

share|improve this answer

In C, I would use the tmpfile() call for a posix system, which would avoid the collision. So I would look for a similar Java call before trying to implement it myself, if you haven't already.

share|improve this answer
This assumes he is the one developing the application – TrueDuality Oct 9 '09 at 15:00
TrueDuality: Ah, my mistake – Kyle Brandt Oct 9 '09 at 15:17
Java has Now with added secure RNG. – Tom Hawtin - tackline Oct 13 '09 at 0:20

Java uses the system property to configure the temporary directory. A reasonable JRE will set that to a sensible value based on the system if not explicitly specified.

share|improve this answer

Your Answer


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.