Compile from source and install it in your home.

Since several months, I would always like to build software from source. It began when I would install vim 8.0 but no packages for Ubuntu were available. I wrote an article about it.

I began by building from source and install it with sudo. But, I had some issues when the package was updated because there were some conflicts.
For these reasons, I decided to build from source and to install the binaries in a separated directory in my home, called $HOME/.bin/. When the binaries are installed in this directory, I only need to extend my PATH with the appropriate subdirectories.

Here some example.

Git

In Ubuntu, the version provided by packages is 2.7.4 from 2016. The current version if 2.13. All source codes I need are in a directory called $HOME/.source. I use the following commands to build git from source and install it locally.

mkdir -p $HOME/.source
git clone https://github.com/git/git $HOME/.source/git
cd $HOME/.source/git
./configure --prefix=$HOME/.bin/git
make -j 8
make install

The usual commands to build C programs are ./configure && make && make install and you can pass some arguments like –prefix=path to ./configure to change the directory where the binaries must be installed.

Emacs

Even if I’m a vim user since several years, I switched to Emacs some months ago. I also want to have the latest version and I use the following commands.

mkdir -p $HOME/.source
git clone https://github.com/emacs-mirror/emacs $HOME/.source/emacs
cd $HOME/.source/emacs
./configure --prefix=$HOME/.bin/emacs
make -j 8
make install

Usually you will easily find the commands to build. If configure is used, you can often use the flag –prefix (it is recommended by the GNU project to always add it when you provide a configure script). I personally recommend it to avoid conflicts and to easily remove the version you don’t want to use anymore.

Hope it can help you.

How to configure and install vim from source?

Vim 8.0 has been released some weeks ago and maybe you want to install it. Sometimes, binaries in packages are often not up-to-date or not configured with python. Here the command to install it from source with python et python3 options (useful if you use YouCompleteMe):

git clone https://github.com/vim/vim
cd vim
./configure --enable-pythoninterp --enable-python3interp
make
sudo make install

You can also add other options. You can list them with:

./configure --help

Personally, I use the following flags

./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp=yes \
            --enable-pythoninterp=yes \
            --enable-python3interp=yes \
            --enable-perlinterp=yes \
            --enable-luainterp=yes \
            --enable-gui=gtk2 \
            --enable-cscope \
            --prefix=$INSTALL_COMPILED_DIRECTORY/vim

where $INSTALL_COMPILED_DIRECTORY is another directory in my home where the binaries will be installed instead of /usr. In this case, I don’t need to use sudo and it doesn’t affect the standard installation of vim.