34

Ubuntu's packages can be pretty old, but for some desktop programs (like Vim) I'd much rather have the latest version, as newer versions often fix various bugs.

How can I get a reasonably recent Vim version on Ubuntu?

47

You have three different options:

  • Wait for the newest versions to be added to the distribution packages. Note that you might want to learn a new language or build a ship with your bare hands while you wait.

If waiting several years is not good for you then you have the following two options:

  • Use a PPA containing the latest version:
    • Pros:
      • Easy to do.
      • Totally automated.
      • Let you install Vim as any other software.
    • Cons:
      • You basically grant root privileges to a complete stranger.
      • This method only works on Ubuntu and the derived distributions using PPA system.
  • Build Vim from sources:
    • Pros:
      • You get a fine tuning of the options you enable (gui, Python/Lua support, etc.).
      • You get the bleeding edge version and don't need any third party maintainer to get it.
      • It's always useful to learn how to compile a software from sources.
      • This is a distribution agnostic method.
    • Cons:
      • Not as automated as the PPA option.
      • Can be frightening for a new user.

In two latter cases, here is a procedure for these options:


PPA

Here is an online tutorial on tipsonubuntu.com (Thanks @joeytwiddle who suggested it in the comments).

First open a terminal and use the following command. This will add the Personal Packet Archive (PPA) maintained by joathonf to you repos and let Ubuntu know where to look for Vim:

sudo add-apt-repository ppa:jonathonf/vim

I'll repeat here that doing this give the root privileges to the scripts in this PPA, do it only if you trust it. You may want to read are PPA's safe to add to my system and what are some “red flags” to watch out for? and is there any guarantee that software from Launchpad PPAs is free from viruses and backdoor threats?.

Update the packet list so Ubuntu will look in the PPA to find the Vim files:

sudo apt update

Finally install vim:

sudo apt install vim

And tada! Vim is installed. Note that you can also do that from the GUI package manager.

Note that this is not the only PPA available with newer Vim versions, you can use your favourite search engine to find more (and do remember you are trusting some stranger from the internet with root access to your system).


Building from sources

A second option is to build Vim from sources. This implies some additional manipulation and can be frightening for a new user, but it is the best way to get the lasted build.

There are several online resources to guide you through this procedure:

A general procedure is the following, you might need to tweak it to fit your needs but the main idea is here:

First you might need to install some dependencies. For example use this command (suggested by YouCompleteMe wiki):

sudo apt-get update
sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \
    libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
    libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
    python3-dev ruby-dev lua5.1 lua5.1-dev libperl-dev git

Note that you maybe won't need everything: for example if you won't use Lua, do not include lua5.1-dev to the list.

Edit Instead of using the previous apt-get install command you can use the following. It has the advantage of automatically handling the dependencies you need:

sudo apt-get build-dep vim

Then get the sources on your computer (you'll need the git command installed with apt-get install git):

git clone https://github.com/vim/vim.git

Go to this directory and 'pull' the last changes:

cd vim
git pull

If you have an error on git pull because you already made changes you can 'stash' your modifications (i.e. remove them temporarily), pull the changes and then restore your modifications. If you did so I'll assume that you are familiar with git and won't provide the procedure to follow (it is detailed in the vim.org doc).

You can then build Vim as you would build any other software from sources. The file src/INSTALL should provide you with the information you need to compile Vim.

A regular workflow would begin with:

./configure --with-features=huge --enable-gui=auto

Remove --enable-gui if you don't want gVim.

If you don't have root access on the machine you're installing Vim, you might want to add the --prefix option which allows you to use a directory where you have access rights. For example you could use:

./configure --with-features=huge --enable-gui=auto --prefix=$HOME/local/vim

The configure script can take a lot of arguments to tune which features you want to enable. Running it takes a while. While running, it prints messages telling which features it is checking for.

Once it is configured, you can compile the program with:

make

An optional command exists to run some self-checks (don't ask me what they do exactly I always skip them :-)):

make check

Finally install Vim to /usr/local/ (this command requires the root privileges):

sudo make install

To remove the now useless files which were created for the compilation you can then run:

make clean
make distclean

And here you are with a fresh Vim install.

You will probably want to remove any Vim you've installed from the Ubuntu repo, but you don't need to. By default, Vim will install to /usr/local/, rather than /usr/. Just make sure you're running the correct Vim version (i.e. /usr/local/bin/vim, and not /usr/bin/vim).

  • 1
    Regarding dependencies, sudo apt-get build-dep vim is even simpler to use. Otherwise, I'd have added a note about --prefix as not all of us have root privilege, which is quite common. – Luc Hermitte Jan 3 '17 at 12:36
  • @LucHermitte thanks for these suggestions. Regarding apt-get build-dep vim you mean to use it in the last step of the PPA installation, right? Now about --prefix that is indeed an important note to add: is --prefix=/usr a safe place to advise or would you recommend another directory (e.g. --prefix=~/bin)? – statox Jan 3 '17 at 14:24
  • The build-dep command can be used instead of sudo apt-get install libncurses5-dev ..... Regarding --preffix, its typical use is: --prefix=$HOME, but lately I've being using --prefix=$HOME/local/vim. This way, uninstalling a software is as easy as a rm -r and removing a couple of lines in the .profile/.bashrc – Luc Hermitte Jan 3 '17 at 14:34
  • @LucHermitte Ok for prefix. For build-dep I have to say that I'm not that familiar with this command so I'm afraid I don't understand properly: From what I understand apt-get build-dep vim would install the dependencies for the package vim. But here as we dont have the newest vim package in the packages sources (since we are building from the sources) how will the command install the correct dependencies? If I'm trying to build Vim8 from sources and my package list contains vim7.4, apt-get build-dep vim will install the dependencies of vim7.4 right? (I can't test it right now, sorry) – statox Jan 3 '17 at 14:44
  • It will install the dependencies we need in order to compile vim source code that we can obtain from github. This way we don't need to track down all the libraries used by Vim source code. As long as the source code we are compiling doesn't depend on a non-packaged version of a library, this is perfectly fine. – Luc Hermitte Jan 3 '17 at 14:50
2
#!/usr/bin/env bash

sudo apt update

sudo apt install -y git

sudo apt install -y build-essential

rm -fr /tmp/vim

git clone https://github.com/vim/vim.git /tmp/vim

make -C /tmp/vim

sudo make install -C /tmp/vim 

rm -fr /tmp/vim
  • 5
    Welcome to the site! It might be helpful to describe what this is, what it does, and how to use it. Not everyone who reads this will be familiar with the commands you use or writing/using bash scripts, git, and package managers. I can see from your edits that you've already done a good job of doing so elsewhere! – Rich Oct 27 '17 at 9:45
  • For those who do know what it's doing, it works great, /usr/local/bin/vim is quickly ready to go. Your existing /usr/bin/vim is left in place. – rshdev May 13 at 2:01
1

Another option is to install Homebrew on Linix as an alternate package manager and use it to install the latest vim with:

brew install vim

Homebrew Features:

  • Can install software to your home directory and so does not require sudo
  • Install software not packaged by your host distribution
  • Install up-to-date versions of software when your host distribution is old
  • Use the same package manager to manage your macOS, Linux, and Windows systems
New contributor
David Hatch is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Welcome to our site David! I have trouble seeing how homebrew solves this problem: Are the homebrew repositories more up to date than apt's ones? – statox 2 days ago
  • @statox Yes, the homebrew repositories are generally newest version. – David Hatch yesterday
  • Ok, good to know :) – statox 14 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.