This article describes how to build Vim (vim and gvim) from the source and compile it against a predefined version of ruby installed with rbenv. In the first chapter I’m describing how to build it from source for Ubuntu. The second part describes how to build for MacVim.
By installing Vim with ruby support from the sources, it is build against the system wide installation of ruby. If you already installed Vim and/or ruby with
sudo apt-get install vim (or
sudo apt-get install ruby) or with
brew install vim (e.g.
brew install ruby) if you are using OS X, remove it completely from your system to install the latest version of Vim.
I’m installing rbenv on different machines I created the following script (named rbenv_install.sh) to install ruby 1.9.2-p320:
cd $HOME sudo rm -rf .rbenv git clone git://github.com/sstephenson/rbenv.git .rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile # install steps for rbenv-install command cd $HOME/Downloads sudo rm -rf ruby-build git clone git://github.com/sstephenson/ruby-build.git cd ruby-build sudo bash install.sh # updating the current shell cd $HOME exec $SHELL source $HOME/.bash_profile rbenv-install 1.9.2-p290 rbenv rehash exec $SHELL
After this try the following:
$ rbenv global 1.9.2-p320 $ rbenv local 1.9.2-p320 $ ruby -v => ruby 1.9.2p320 (2012-04-20 revision 35421) [i686-linux]
Get the latest version of Python
This will be put in the
cd /tmp wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 tar xjvf Python-2.7.3.tar.bz2 cd Python-2.7.3 ./configure --prefix=$HOME make && make install make inclinstall hash -r # cleanup cd /tmp && rm -rf Python-2.7.3
Get the latest version of Vim
$ cd $HOME/Downloads $ wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2 $ tar -xjvf vim-7.4.tar.bz2
You can also get the latest Vim version from the git repository https://github.com/b4winckler/vim and checkout the latest tag you want to have.
Compiling Vim and Gvim
To install Gvim on Ubuntu we need to install additional packages on our machine. The following snippets describe the packages for Ubuntu:
$ sudo apt-get install libncurses-dev libgnome2-dev \ libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev \ libx11-dev libxpm-dev libxt-dev
Next, we need to configure the compilation and make the install:
cd ~/git-repositories/vim && git checkout v7-4-183 && git clean -f ./configure --prefix=/usr/local \ --without-x \ --disable-nls \ --enable-gui=no \ --enable-multibyte \ --enable-rubyinterp \ --enable-luainterp \ --enable-pythoninterp \ --with-python-config-dir=$HOME/lib/python2.7/config \ --enable-gui=gnome2 \ --with-features=huge \ --with-tlib=ncurses \ sudo make && sudo make install && sudo make clean
Let’s get over the heavy stuff:
--prefix=/usr/local- place of the binaries of the installed Vim installation (check the
/usr/local/bin) - there will be the executable binaries
--enable-rubyinterp- says you want to build Vim with the default ruby installation (in our case
--enable-gui=gnome2- building Vim with Gvim support (if you don’t want Gvim than you can leave this line out)
After configuring the compilation check if the console response contains the following terms:
checking --with-ruby-command argument... defaulting to ruby checking for ruby... (cached) /home/mg/.rbenv/shims/ruby checking Ruby version... OK checking Ruby header files... /home/mg/.rbenv/versions/1.9.2-p320/include/ruby-1.9.1
If you can’t see the lovely Ok, your Vim compilation will probably not have ruby support. Maybe you have not installed ruby the right way or some packages are missing on your machine.
Check the installation
Open a new session or perform
exec $SHELL to reboot your Shell. You will see the fresh installed version of Vim:
$ which vim /usr/local/bin/vim $ which gvim /usr/local/bin/gvim
Next check is to get the correct –version of
gvim with the following commands:
$ vim --version | ack ruby $ vim --version | ack python $ gvim --version | ack ruby $ gvim --version | ack python
If both commands return +ruby and +python, you are fine, and got the achievement “I installed vim form source
with ruby support on my own”. You should now be able to run the
Hammer.vim plugin - install it, start it with
:Hammer, install the
missing gems and if you are able to run
:Hammer without any missing dependencies, you have setup everything correct.
Installing MacVim from source
The ways are nearly the same as mentioned above: Install rbenv as mentioned in the steps before.
$ cd $HOME/Download $ git clone git://github.com/b4winckler/macvim.git
Next step is to configure MacVim for OSX:
$ cd macvim/src $ ./configure --prefix=/usr/local \ --with-features=huge \ --enable-rubyinterp \ --enable-pythoninterp \ --enable-perlinterp \ --enable-cscope
After configuring the compilation check the console response after the following terms:
checking --with-ruby-command argument... defaulting to ruby checking for ruby... /Users/helex/.rbenv/shims/ruby checking Ruby version... OK checking Ruby header files... /Users/helex/.rbenv/versions/1.9.2-p320/include/ruby-1.9.1
When this is finished, it is time
build MacVim with make:
Next step is to run the MacVim installation:
The window should open MacVim. Run the following command in the MacVim quickfix window:
:ruby puts "MacVim"
In the next step, you can drop the MacVim.app icon in your Application folder and you are done.
It was a pain to gather the information for building vim by source with rbenv. Duration of finding that was: ~ 6 h. I’m not sure if all of this works on RVM - I just need additional feedback from people using it. Happy “Vim-ing”!