Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

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

share|improve this question
up vote 200 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 "shell variables" you can enter the next command:

( set -o posix ; set ) | less

This will show you not only the shell variables, but the environment variables 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 '15 at 15:01
printenv is an external command, so it only knows about (and prints) exported environment variables. set is an internal bash command, so it shows all the "shell variables" (unexported environment variables) as well as the exported environment variables. – Dan Pritts Jul 30 '15 at 15:33

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… – Gunnar Hjalmarsson Jan 2 '14 at 17:06

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

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

env is a POSIX 7 way:

export asdf=qwer
env | grep asdf

Sample output:


It only shows exported variables: non-exported variables are not usually considered "environment variables".

Prefer that over printenv, which is not POSIX. Both seem to do the same thing without arguments:

share|improve this answer
Already mentioned two years ago: – muru Nov 30 '15 at 15:00
@muru fair enough. Wish it had made env more visible with better formatting, and I've added more info. – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Nov 30 '15 at 15:01
That's what editing is for. – muru Nov 30 '15 at 15:02

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.