Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Including not only $HOME, $PWD etc but any other you have defined.

share|improve this question

5 Answers 5

up vote 78 down vote accepted

Enter the following command in a terminal to print all the environment variables:


For further information about this command, read the printenv man page.

To show a list including the variables created by yourself you can enter the next command:

( set -o posix ; set ) | less

This will show you not only your variables, but the environment var too.

For more information related with this topic read:

share|improve this answer
If I go to the terminal and write MYNEWVARIABLE=Ubuntu and execute printenv it doesn't show there. Why is that, and how do those others show up? –  Strapakowsky Mar 30 '13 at 3:30
@Strapakowsky I was wondering to myself that question, and I found a possible solution. Read my updated answer. –  Lucio Apr 1 '13 at 14:52
Probably you are seeing the difference between a shell variable and an environment variable. Try export MYNEWVARIABLE=Ubuntu and it will work as you expect. –  Rmano Oct 12 '13 at 0:41
if you simply execute set, it lists the variable created by you as well. Or do set | grep myvar –  Serg Jan 4 at 15:01

I know that this question is quite old and answered, but I think I can add a bit of useful information.

In all the methods described above, the procedure that is suggested is:

  • lauch a terminal
  • show the environment variables using env, or printenv or whatever

The problem of these solutions are that you are seeing the environment variables of the shell that is running into the terminal. You are not seeing the environment variables available to an application run, for example, directly by the graphic interface.

This is noticeable if, for example, you use your ~/.profile, or .bashrc, or .zshenv (depending on your shell) to modify the environment variables --- like the classic addition of directories to the path.

To see the environment variables available to the application started directly in the graphic environment, you can do the following (in Gnome Shell, I am sure there is an equivalent method in all the other DE):

  • press Alt-F2
  • run the command xterm -e bash --noprofile --norc

You now have a terminal with a shell that did not add any environment variables. You can use env here to list all your environment variables:

Example of the bare shell

Obviously the new shell will have the environment variables added by the system files, but that variables should be available (by inheritance) to all programs in the system anyway.

I am posting this because it's the fourth time I have to search this trick again, checking my .pam_environment file. So now I will find it faster (and in the process, I hope helping someone else...)

share|improve this answer
Requires you have a desktop environment, not useful for server CLI-only folk. –  K7AAY Oct 21 '13 at 18:21
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot. –  Rmano Oct 21 '13 at 20:36
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/… –  Gunnar Hjalmarsson Jan 2 '14 at 17:06
I would really like to know the reason for the downvote. –  Rmano Mar 8 '14 at 4:02

To list the environment variables in terminal with CTRL+ALT+T you can use env command.

for example :

[raja@localhost ~]$ env


hope that helps.

share|improve this answer

You can see all variables with the declare builtin.

declare -p

If you're only interested in environment variables, use

declare -xp

Run help declare to see what the other options are.

share|improve this answer

In bash using compgen:

compgen -v | while read line; do echo $line=${!line};done  
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.