Compiling and Installing Programs in Your Home Directory

A project’s source code is built in a variety of different ways. This document contains some of the most common ways to build software in your home directory. If you’re having trouble building your software in your home directory and the software you’re trying to build uses a different build system than any of the ones covered in this document, reach out to the Linux Team for assistance so it can be added to this document.

Compiling and Installing in Home Directory

General Setup (Start Here)

  1. Download the archive for the package you want to compile (i.e. somefile.tar.gz).

  2. Extract the archive. As an example, if your archive is a .tar.gz file, you would run:

    1. tar xvf somefile.tar.gz

  3. Check dependencies for the program. To view all packages currently installed on your computer:

    1. On CentOS computers, run: rpm -qa

    2. On Ubuntu computers, run: dpkg -l

  4. Request that dependencies be installed if they are not already installed, or use self-service installation if it has been enabled on your computer.

  5. Create a general directory inside of your home directory for installing all of your compiled programs if it doesn’t already exist:

    1. mkdir $HOME/compiled

  6. Edit the file ~/.bashrc to add the following 6 lines at the end if they do not exist:

    1. Filename: ~/.bashrc

      if [ -z "$LD_LIBRARY_PATH" ]; then export LD_LIBRARY_PATH=$HOME/compiled/lib:$HOME/compiled/lib64 else export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/compiled/lib:$HOME/compiled/lib64 fi export PATH=$PATH:$HOME/compiled/bin
  7. If you needed to add the lines from the previous step, logout and log back in to make the settings take effect.

  8. Change your current directory to the directory created when extracting the archive.

  9. Follow the guide below that corresponds to the build system for your software.

Makefile (make && make install)

  1. Run the make command to compile the software:

    1. PREFIX=$HOME/compiled make

  2. Install the compiled software using ‘make install’:

    1. make install

  3. Your program should be available under the $HOME/compiled/bin directory.

GNU Autoconf (make && make install with ./configure step)

  1.  Configure the package using the install path that you chose in the previous step:

    1. ./configure --prefix=$HOME/compiled

  2. Run the make command to compile the software:

    1. make

  3. Install the compiled software using ‘make install’:

    1. make install

  4. Your program should be available under the $HOME/compiled/bin directory.

CMake

  1. Create and change to the build directory:

    1. mkdir build && cd build

  2. Use CMake to create the Makefile:

    1. cmake -DCMAKE_INSTALL_PREFIX:PATH=$HOME/compiled ..

  3. Build and install the program:

    1. make && make install

Useful Environment Variables

Your computer uses various environment variables to tell it where to look for things like programs and libraries. Programs and libraries installed from the package manager do not need these variables edited since they are installed to the default locations that are present in those variables. When you compile these in your home directory, however, you will need to adjust them. These can be set either in the ~/.bashrc file, or for any single command by running a command with the variable defined before (e.g. “VARIABLE=value mycommand”). Here are some common environment variables you may need to work with:

  • PATH: List of directories to look for programs in

  • LD_LIBRARY_PATH: List of directories to look for library files in

  • C_INCLUDE_PATH and CPLUS_INCLUDE_PATH: for linking header files

Tips and Tricks

  • When trying to compile software with libraries compiled in your home directory, remember to set LD_LIBRARY_PATH and set C_INCLUDE_PATH or CPLUS_INCLUDE_PATH or use the  -I and -L flags for gcc.