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?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
You have three different options:
If waiting several years is not good for you then you have the following two options:
In two latter cases, here is a procedure for these options:
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).
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
--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
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:
An optional command exists to run some self-checks (don't ask me what they do exactly I always skip them :-)):
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/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