18

How to list all the environment variables in Linux?

When I type the command env or printenv it gives me lots of variables, but some variables like LD_LIBRARY_PATH and PKG_CONFIG don't show up in this list.

I want to type a command that list all the environment variables including this variables (LD_LIBRARY_PATH and PKG_CONFIG)

7
  • Why do you think that those should have values? Commented Jan 14, 2014 at 19:33
  • Because I add values to them Commented Jan 14, 2014 at 19:50
  • 1
    If they don't show up, then not correctly. Commented Jan 14, 2014 at 20:01
  • 1
    The GNU standards recommend installing by default all libraries in /usr/local/lib....
    – sager89
    Commented Jan 14, 2014 at 20:04
  • You may also want to read this first: cc.dtu.dk/?page_id=304
    – sager89
    Commented Jan 14, 2014 at 20:14

3 Answers 3

13

env does list all environment variables.

If LD_LIBRARY_PATH is not there, then that variable was not declared; or was declared but not exported, so that child processes do not inherit it.

If you are setting LD_LIBRARY_PATH in your shell start-up files, like .bash_profile or .bashrc make sure it is exported:

export LD_LIBRARY_PATH
12

try

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

This will modify the variable.

To print it, type: echo $LD_LIBRARY_PATH and it should show the above value.

If you're seeing nothing when you print that, then the variable might not be set.

2

The question in fact is a good question. when run env or printenv, the output will be the system environment, but LD_LIBRARY_PATH is not belong to.

For example, if you set a=1, you can't show it by env. Same as LD_LIBRARY_PATH, it is used by ld.so only(ld. so – this little program that starts all your applications)

Not the answer you're looking for? Browse other questions tagged or ask your own question.