Compile & install vim on a shared host

Many developers just can’t live without a CLI based editor, that being vi, nano or perhaps even pico.
And I myself, is no exception. However today I found myself in the need of vim, mostly because it’s way easier to configure contrary to vi.

For those not enlightened yet, vim stands for vimproved.

Some day you might find yourself in a similar situation, you tunnel through a ssh connection to you hosting provider type the vim  command.. and instantly you’re faced with this message:

vim: command not found.

So, without further ado, here’s the commands you need to run in order to get a working copy of vim installed.

Replace the version number, or head to the official vim public ftp to grab the link for download.

# Download the latest version of vim.
$ wget

# Extract the downloaded archive
$ tar -jxf vim-7.4.tar.bz2

# No need for the archive file, once extracted
$ rm vim-7.4.tar.bz2

# Change directory to vim source files
$ cd vim74/src
And here’s the smart part, since we’re most likely not going to have root access in order to install vim, we will have to change the installation directory for this installation, to a directory belonging to your *nix account.

# Ovveride configuration location by specifying a prefix
$ ./configure --prefix=/home/<USERNAME>/bin/vim

Of course you’d have to make sure that the path you specify, actually exists and is writeable by your account.
Also this path is required to be absolute.
Generally for projects, it is very common to provide different options to override different locations. By standard, --prefix overrides all of them, so you need to override config location after specifying the prefix. This course of actions usually works for every automake-based project.
Eventually do  configure --help and see what other options are available.

At this point we’re only left with compiling the binaries needed.

# Build the vim binaries
$ make && make install
# No need for the source files, once compiled
$ rm -r vim74/
You’ll have to wait a little while for this to complete, depending on resources allocated to you this can take between 5 and 20 minutes.
Once done, you’ll be left with the compiled binaries in bin/vim/ within the current working directory.
The following step is not required, but i highly recommend doing it for ease of use.
Whether you want to use .profile, .bash_profile or .bashrc is up to you. I usually just go with .bashrc
# Edit your bash profile
$ vi ~/.bashrc

Add this line:

alias vim="/home/<USERNAME>/bin/vim/bin/vim"
Again make sure the path is correct, and matches the location, of your just compiled binaries.
If you also want to override vi, and use vim instead, you could also add this alias, AFTER the above line.
alias vi="vim"
If you ommit the above alias, you’ll be left with two different editors, vi, and vim alongside each other.
# Finally source your profile, to make changes effective immediately
$ source ~/.bashrc

For extra sugar you could create .vimrc file in your home directory, and add syntax on to it, to enable syntax highligthing when using vim.


Nerd Alert!

With this setup you’ll only be able to use vim in interactive shells meaning that script shells such as $ git commit won’t be able to use vim, if configured so, to workaround this you’ll have to add the vim binary directory to you environment variables, by changing your PATH variable.
Add this to your .bash_profile
export PATH
Thanks for reading, that would be all for now.