How to compile locally on linux without sudo permissions

Here’s an example of how to compile things locally on linux without sudo permissions.

Why in the world would you want to do this? Well you might be on locked down system (say you are at school) and the back and forth between the sys admins may not be effective.

For example, I have been trying to get Caffe to work with Python on my locked down machine at school – and while the sys admins were helpful enough to install Caffe, I was getting strange errors using different versions of Caffe with the different versions of python installed. Here’s how I solved one problem, which I hope is a useful template and reminder for future issues.

[Disclaimer: I’m a total beginner with Linux so this may be a terrible idea…]

First, let’s try to import Caffe into Python.

$ python
>>> import caffe
ImportError: cannot open shared object file: No such file or directory

As I’m getting a lot of these types of errors, I thought I would try to debug this myself without sudo. Basically, I’m gong to compile the needed package from source, and then manually link the file.

Alright, let’s download and install this package from source (following this link):

$ git clone
$ cd /local-scratch/jer/site-packages/mdb/libraries/liblmdb/
$ make

Cool okay looks like it worked. Let’s go into the Makefile and change the path to install to a location I can write to (in this case I can write to /local-scratch/jer/site-packages/, you will have to modify the below examples for your path).

vi Makefile

# Changed the "prefix" to my local directory where I can write to
prefix = /local-scratch/jer/site-packages

Exiting the editor, we then create two additional folders.

$ mkdir /local-scratch/jer/site-packages/bin
$ mkdir /local-scratch/jer/site-packages/lib

And then install the necessary libraries:

$ make install

Hopefully this works. You should now have the necessary libraries installed locally and can verify by:

$ ls /local-scratch/jer/site-packages/lib/

Now let’s add this directory to our path:
(note that this will disappear in each new instance of the terminal)
(also note that this is how you do this for Csh, you might need to change if you are in a different shell)

$ setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH\:/local-scratch/jer/site-packages/lib

Alright, now let’s try importing Caffe again:

$ python
>>> import caffe
ImportError: cannot open shared object file: No such file or directory
>>> exit()

No cigar… hmmm… I think to myself, this extension seems strange… let’s try re-naming our lib file to match this…

$ cd /local-scratch/jer/site-packages/lib
$ mv

And now try to import Caffe again:

$ python
>>> import caffe

Yay! No errors. Well it looks like this is some temporary hack that works if you are working on a locked down system. Again, I’ll repeat the earlier disclaimer that I’m a total linux beginner… and this may be an awful solution, but at least it is a temporary solution 🙂