Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Right now pkg-config looks only in /usr/lib/pkgconfig. I can adjust it for a user by exporting the PKG_CONFIG_PATH environment variable, but once again I forgot to do it for root and wasted time wondering, why my plugin is not installed properly (the makefile used pkg-config). So how can set it system wide, so it would always look in to both /usr/lib and /usr/local/lib?

share|improve this question
up vote 2 down vote accepted

The traditional place to define an environment variable system-wide is /etc/profile. This file is read by Bourne-style shells (including bash, ksh, ash) when you log in for a text-mode session, either locally (on a text mode console) or remotely (over ssh). If you log in in a graphical environment, /etc/profile may or may not be read, depending on your login manager, desktop environment and operating system distribution.

A better method, if available on your system, is to define the environment variable in /etc/environment. This file is read by PAM, specifically by the pam_env module. These variables are available in all sessions started by a login method that uses PAM and has the pam_env module referenced in /etc/pam.conf or /etc/pam.d/$method.

share|improve this answer

Probably the easiest, although not 100% reliable way would be to add it to /etc/bashrc.

It's not reliable because any individual user can set to not process /etc/bashrc.

If you want to go the more complex way, you can create a wrapper that will set it. First you rename pkg-config to pkg-config-real, then make a new script named pkg-config that will set the variable.

(As root, or use sudo)

cd /usr/bin
mv pkg-config pkg-config-real

Then make a new file in /usr/bin/pkg-config with the following contents:

export PKG_CONFIG_PATH=/usr/lib:/usr/local/lib
pkg-config-real $*

Be sure to make it executable.

chmod 755 pkg-config
share|improve this answer
/etc/bashrc isn't the right place, see Difference between .bashrc and .bash_profile. You should not recommend modifying a file in /usr/bin; it would be better to create /usr/local/bin/pkg-config and call /usr/bin/pkg-config from there. In your script, you must use "$@", not $*; further improvements: #!/bin/sh and exec pkg-config-real. – Gilles Aug 6 '11 at 18:06

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.