I wanted to set environment variables JAVA_HOME and PATH. So I wanted to open ~/.pam_environment since it is the best place to set environment variables relevant to a particular user according to the link https://help.ubuntu.com/community/EnvironmentVariables.

The link states:

Session-wide environment variables

Environment variable settings that should affect just a particular user (rather then the >system as a whole) should be set into:

~/.pam_environment - This file is specifically meant for setting a user's
environment. It is not a script file, but rather consists of assignment expressions, one per line.

The problem I have is that I am not able to open the file ~/.pam_environment by using the command gedit ~/.pam_environment.

I do not know whether this is the right way to open this file, please point me in the right direction.

  • 1
    I am having this problem too. Even for me the file .pam_environment doesn't exist. I too referred to the same link. One good point to note is that you can press Ctrl + H to show the hidden files. This is a general recommendation - it won't solve your current problem as the file is simply not there. May 26, 2012 at 7:26
  • 12
    If it does not exist you create it...
    – Rinzwind
    May 26, 2012 at 8:05

2 Answers 2


Note that .pam_environment does not use the normal syntax. You should strictly follow the pam_env.conf syntax.

In particular if you want to set the JAVA_HOME and PATH variables you can put this content into your .pam_environment:

JAVA_HOME DEFAULT=<the-path-to-java-home
PATH DEFAULT=${PATH}:extend/the:path

Following Rinzwind answer will most likely brick your login[1]. In which case you can re login into a TTY using Ctrl + Alt + F1 and remove the .pam_environment file with the command:

/bin/rm ~/.pam_environment

[1] At least on my computer with Kubuntu 12.04


I was having a similar issue with this. Specifically the concept of locating, or otherwise creating, the .pam_environment file.

This is the route I followed, courtesy of Deepu Mohan Puthrote's blog post (Link below):

Step One: In your GUI (Graphical User Interface) Locate the file in your 'home' directory called '.pam_environment.' NOTE: Pam_environment is a hidden file, to make it and other files/directories visible press 'Ctrl+H.' If pam_environment does not exist, continue to step two. If pam_environment does exists, skip to step three.

Step Two: This is how you create your pam_environment file. Open your CLI (bash, terminal, or whatever you want to call it) and make sure you are in your home directory (I.e /home/yourname), you can do this with the 'pwd' (print working directory) command. If you are not in your home directory, input 'cd' to revert to your home directory.

Now create the file in question with the following command:

touch ~/.pam_environment

Step Three: In your GUI, open '.pam_environment' in your home directory (remember to make hidden files visible if necessary). When opened, you can input the the commands into the text editor which will create your session wide environment.

For 'PATH' (which I was learning to set) I used something like:

PATH=$PATH:~/usr/sbin:/usr/bin/<----add your directory here ---->

Step Four: Now restart your computer and, if your computer is as old as mine, go make a cup of tea.

Now check that your change has worked. Open your CLI and run the command 'printenv PATH.' Unless I have failed you, you have just successfully created a session wide PATH variable; you should see the PATH variable, or a variant of, displayed on screen with the new value you have defined in your .pam_environment file.

For reference: http://tech.deepumohan.com/2012/12/how-to-set-environment-variable-in.html

  • 1
    ~/.pam_environment requires a special syntax for variable expansion to work; see Bakuriu's answer. Nov 24, 2014 at 16:42

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.