The usual method for building GLFW on Ubuntu from source is like so:

make x11
sudo make x11-dist-install

Assuming you’ve got the proper libraries installed for compiling, everything should go smoothly and the compiled libraries will be put in system directories.

If you’re missing libraries needed to compile, try installing them with this command:

sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev xorg-dev

If you’re using Nvidia proprietary drivers or otherwise already have OpenGL headers, you really only need build-essential and xorg-dev.

So now you’ve compiled and installed GLFW. Everything is grand right? You can compile programs using the GLFW library. However if you try to run one of them (on Ubuntu 12.04 in my case), you get this message:

error while loading shared libraries: libglfw.so: cannot open shared object file: No such file or directory

This is because the GLFW installer puts libglfw.so in /usr/local/lib instead of /usr/lib like Ubuntu expects. But /usr/local/lib is a fine place to put shared libraries for most of the Unix world, so let’s just tell Ubuntu to look there when linking our program. You’ll want to edit /etc/ld.so.conf and add the line “/usr/local/lib” to the file, then save. Afterwards you should run ldconfig as root. Something like this:

sudo nano /etc/ld.so.conf #opens in nano as root for editing, ctrl+o to save
sudo ldconfig

Once that is done, your GLFW programs should open and run as expected.