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)
Download the archive for the package you want to compile (i.e. somefile.tar.gz).
Extract the archive. As an example, if your archive is a .tar.gz file, you would run:
tar xvf somefile.tar.gz
Check dependencies for the program. To view all packages currently installed on your computer:
On CentOS computers, run:
rpm -qa
On Ubuntu computers, run:
dpkg -l
Request that dependencies be installed if they are not already installed, or use self-service installation if it has been enabled on your computer.
Create a general directory inside of your home directory for installing all of your compiled programs if it doesn’t already exist:
mkdir $HOME/compiled
Edit the file ~/.bashrc to add the following 6 lines at the end if they do not exist:
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
If you needed to add the lines from the previous step, logout and log back in to make the settings take effect.
Change your current directory to the directory created when extracting the archive.
Follow the guide below that corresponds to the build system for your software.
Makefile (make && make install)
Run the make command to compile the software:
PREFIX=$HOME/compiled make
Install the compiled software using ‘make install’:
make install
Your program should be available under the $HOME/compiled/bin directory.
GNU Autoconf (make && make install with ./configure step)
Configure the package using the install path that you chose in the previous step:
./configure --prefix=$HOME/compiled
Run the make command to compile the software:
make
Install the compiled software using ‘make install’:
make install
Your program should be available under the $HOME/compiled/bin directory.
CMake
Create and change to the build directory:
mkdir build && cd build
Use CMake to create the Makefile:
cmake -DCMAKE_INSTALL_PREFIX:PATH=$HOME/compiled ..
Build and install the program:
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 inLD_LIBRARY_PATH
: List of directories to look for library files inC_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 setC_INCLUDE_PATH
orCPLUS_INCLUDE_PATH
or use the-I
and-L
flags forgcc
.