This post demonstrates how to install software from source on a Linux system on which the user does not have root access. We will walk through the installation of Emacs & tmux. For this example, we’ll assume the user has created a folder named local in their /home/username/ directory to which Emacs and tmux will be installed.

Installing Emacs

We’ll start with Emacs. Download the latest source archive here, and copy it to /home/username/. Extract the contents of the source archive (assuming we’ve downloaded emacs-24.5.tar.gz):

$ tar -xzvf emacs-24.5.tar.gz 

An emacs-24.5 folder will be extracted to the directory in which you initially copied the source archive.
We’re going to cd into the emacs-24.5 folder and run the configure script, making sure to specify the desired installation location by passing the path (/home/username/local) to the —prefix flag:

$ cd emacs-22.1
$ ./configure --prefix=/home/username/local

Upon successful completion, a Makefile will be created in the same directory configure was called from. Run the Makefile:

$ make && make install

If all goes as planned, emacs should be present in /home/username/local/bin.

In order to use applications installed to the local directory from any directory location, append /home/username/local/bin to the PATH environmental variable. Open up the .bashrc file present in /home/username, and at the bottom, add:

export PATH=${PATH}:/home/username/local/bin

If .bashrc doesn’t exist in your home directory, you can create it.

Save .bashrc, then either logout and log back in to the terminal, or run the following:

$ source .bashrc

Now, running emacs --version should generate the following output:

$ emacs --version
GNU Emacs 24.5.1
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Installing tmux

Installing tmux is slightly more difficult due to a dependency on the libevent library, which wasn’t pre-installed in my case. If libevent is present in your /usr/lib directory, there’s no need to download and install it. You can skip to the tmux Installation section.

libevent Installation

Assuming the /home/username/local directory discussed in the Emacs walkthrough has been created, we’re going to create a few additional directories. First, check in /home/username/local to determine whether it contains a bin directory. If it exists, do not recreate it. If it does not exist, run the following from the shell:

$ mkdir /home/username/local/bin

Next, create two additional directories: /home/username/local/include and /home/username/local/lib:

$ mkdir /home/username/local/include
$ mkdir /home/username/local/lib

lib will contain the actual libevent library, and include will hold the header files associated with libevent.

To verify that all necessary directories have been created, run:

$ cd /home/username/local
$ ls -1
# should output =>
bin
include
lib

Your output should look identical.

Next, cd into the directory to where the libevent archive was downloaded. Here, we’ll assume we’ve downloaded libevent-2.1.18-stable.tar.gz to the /home/username directory. Once there, run the following:

$ cd /home/username
$ tar -xzvf libevent-2.1.18-stable.tar.gz
$ cd libevent-2.1.18-stable

We extracted the libevent archive, and cd’d into the extracted folder.

Within the libevent-2.1.18-stable folder, there exists a script named configure. Run the configure script with an additional argument indicating where the library should install itself. Since we want it installed to /home/username/local, run:

$ ./configure --prefix=/home/username/local

If you omit the --prefix=path flag and you do not have root access, configure would exit with an error, without installing anything.

After configure completes and the prompt is returned (you’ll see a lot of text output to the terminal as configure runs), run the make command:

$ make && make install

configure checks whether or not all build dependencies have been satisfied, and make tells the compiler and linker how to build/install the application/library.

After make completes, you should see libevent installed to /home/username/local/lib.

Next, we’ll follow roughly the same process to install tmux.

tmux Installation

From the terminal, change directory back to where you downloaded the source archives (in our case, /home/username). Feel free to delete the libevent files and folders in /home/username.

$ cd /home/username
$ rm –rf *libevent*

Next, extract the tmux source directory like we did for libevent, then cd into the extracted directory:

$ tar –xzvf tmux-2.3.tar.gz
$ cd tmux-2.3

Within the tmux-2.3 folder, again you’ll find a configure script. It should be run with the same prefix used earlier. But prior to running configure, we need to specify the location of libevent and its associated header files (the include directory), otherwise tmux will fail to build and will not install, since it will not find libevent in the system-wide library folders.

The command that follows looks complicated, but it’s pretty straightforward. Here’s a description of the components:

env Let’s you modify the environment in which configure will run by passing in variable definitions.
CPPFLAGS tells the linker where to look for libevent’s header files.
LDFLAGS tells the linker where libevent is located.

Enter and execute the following. Don’t forget the single quotes, and no spaces on either side of =. (As a quick sanity check, you should still be in /home/username/tmux-2.3. Verify this by running pwd).

$ env CPPFLAGS='-I/home/username/local/include' LDFLAGS='-L/home/username/local/lib' ./configure --prefix=/home/username/local

A bunch of text will be generated. configure checks to make sure you have everything that’s needed to install tmux. (If you tried installing tmux prior to installing libevent, configure would have generated an error indicating that libevent wasn’t installed or isn’t available). After configure completes and the prompt is returned, you’re going to run the make command, just as before:

$ make && make install

After make completes, you will find that tmux should be installed to /home/username/local/bin.

Updating System Path

Lastly, we need to update the system PATH environmental variable in .bashrc so tmux can be called from bash without having to provide the absolute path to the executable each time you call it. If you didn’t do it for the Emacs install above, carry out the following:

Open up the .bashrc file present in /home/username, and at the bottom, add:

export PATH=${PATH}:/home/username/local/bin

In order to use applications installed to the local directory from any directory location, append /home/username/local/bin to the PATH environmental variable. Open up the .bashrc file present in /home/username, and at the bottom, add:

export PATH=${PATH}:/home/username/local/bin

Save .bashrc, then either logout and log back in to the terminal, or run the following:

$ source .bashrc

Now, running tmux -V should generate the following output:

$ tmux -V
tmux 2.3

That’s it!

In this post, we covered how to install applications from source on Linux without root access. Package managers should be used in situations in which they are available, but when they’re not, installing from source may be your only option. Happy coding!