Install Vim on Ubuntu
Installation

How to Install Vim in Ubuntu

Pranav Krishna
Pranav Krishna

Table of Contents

The versatile text editor everyone is ready to taunt and post memes about, but nobody is willing to learn. Yes, it's none other than the Vim text editor.

For most users, it must be installed in your system by default but due to some reason, if it is not there, it can be installed using a single command:

sudo apt install vim

Once done, you can check the installed version using the following:

Ubuntu 18.04 Review of New Features
Ubuntu 18.04 Review of New Features
vim --version

While writing, it gave me VIM version 8.2:

Detailed info of the version

But what if you want to use the most recent version of VIM? Well, in this guide I'll be sharing multiple methods to do so.

Getting the latest version of Vim (if you really need it)

The latest version of Vim is not found in the official repositories, but there's a workaround for that.

And in this tutorial, I will be sharing 3 ways to get the latest version of VIM:

  • Using a PPA (Recommended)
  • Using Homebrew
  • Installing VIM from the source

1. Using a PPA

Using PPA in Ubuntu is preferred when you don't get the desired package from the default repository.

So let's start with adding PPA to the system:

sudo add-apt-repository ppa:jonathonf/vim

Once done, update the repositories and install Vim using the following command:

sudo apt update && sudo apt install vim

This command upgrades your Vim installation if it is already present, and creates no conflicts, fortunately.

Now the current version of Vim is found to be 9.0, the latest.

Newer version of Vim
Vim (newer version) 9.0

How to uninstall

To remove VIM, all you have to do is use the normal apt remove command that you generally use for the removal of the package:

sudo apt remove vim 

Once done, you may also want to remove PPA from Ubuntu which can easily be done using the following command:

sudo add-apt-repository -r ppa:jonathonf/vim

To learn more about how PPA works, I would highly recommend you our detailed guide covering all the major aspects of the PPA:

What is PPA? Everything You Need to Know About PPA in Linux
An in-depth article that covers almost all the questions around using PPA in Ubuntu and other Linux distributions.

2. Using Homebrew

An advantage of installing it from a package manager like this leads to the automatic updating of the package(s) if there's a newer version. This seems more convenient than directly sourcing from GitHub.

Homebrew is a versatile package manager available for Mac OS and Linux. You can install Homebrew in Ubuntu seamlessly:

Installing and Using Homebrew Package Manager on Linux
Homebrew, also known as Brew, is a command line package manager primarily created for macOS. Homebrew grew quite popular among macOS users as more developers created command line tools that could be easily installed with Homebrew. This popularity resulted in the creation of Linuxbrew, a Li…

Once done, the latest Vim can be obtained by the below command:

brew install vim
Obtaining Vim via Homebrew using 'brew install vim'
Obtaining Vim via Homebrew

This command also creates no conflicts and it upgrades Vim seamlessly. This upgrades to the absolute latest version of Vim available.

Latest Vim (v9.0.1450) installed via Homebrew
The latest Vim 9.0

How to uninstall

Homebrew makes package management quite easy so for the removal of VIM, all you have to do is execute the following command:

brew remove vim
Removing Vim from Homebrew
Removal of Vim (Homebrew)
⚠️
Make sure to remove existing VIM from your system before following this method as if you forgot to do so, it will lead to clashes and making errors.

The source code for Vim is available on its GitHub page, from where we will be downloading and compiling it manually.

For that, you will need to install git and GNU Make in your system if not already present, which is done by

sudo apt install git make ncurses-dev

Then, you have to download the source code and clone it into the folder as shown below:

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

Next, switch to the source directory of the cloned repo:

cd ./vim/src

Now, you can use the following command to build the package as per defined in the makefile:

make

And finally, you can use install the build package using the given command:

sudo make install

That's it, you have the latest version of VIM installed in your system.

How to uninstall

If you installed VIM from the scratch, you can use the shown steps to for removal.

First, you'd have to use a VIMRUNTIMEDIR variable that defines the directory where the support files are located.

To do so, you'd have to identify the directory name which will be different based on the version using the following command:

find /usr/share/vim/ -type d -name "vim*"

The second result is what we are looking for:

find location where the vim is installed

In my case, its /usr/share/vim/vim82 but the last two digits can be different in your case.

Once you find yours, use the following command:

make VIMRUNTIMEDIR=/path/to/vim

In my case, it will be the following:

make VIMRUNTIMEDIR=/usr/share/vim/vim82

And finally use the following command to remove VIM:

sudo make uninstall

That's it!

Want to learn more about installing packages from source?

If you're curious and want to learn more about how you can install packages from source in different scenarios, you can refer to our detailed guide on that topic:

How to Install Software from Source Code… and Remove it Afterwards
Brief: This detailed guide explains how to install a program from source code in Linux and how to remove the software installed from the source code. One of the greatest strength of your Linux distribution is its package manager and the associated software repository. With them, you have all th…

I hope you will find this guide helpful.

And if you have any queries, feel free to ask in the comments.



Pranav Krishna

Pranav Krishna

This is Pranav Krishna, a Proud Linux user in twelfth grade.