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

I'm on Ubuntu 10.10, and I've just upgraded opencv to 2.4.2.

The problem is that each time I open a new shell and try to compile and run, it compiles but doesn't run due to the following error:

./a.out: error while loading shared libraries: cannot open shared object file: No such file or directory

As far as I can see, this file is located in /usr/local/lib/!

I can get it to run by running the following beforehand:

export LD_LIBRARY_PATH=/usr/local/lib

How can I fix this issue?

share|improve this question
up vote 3 down vote accepted

/usr/local/lib is not in the default Ubuntu path. You should add it at the end of the LD_LIBRARY_PATH environment variable in /etc/environment. Reboot and the new path will be effective.

You can also set this on a per-user basis in ~/.bashrc

Example (/etc/environment)


Example (~/.bashrc)

export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"
share|improve this answer
I upvoted, but actually it seems like running ldconfig as root is the "right" way to do this: – j_random_hacker Apr 21 '15 at 14:47

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.