sodcalculator

10 Tech How-To

How to Install Vim on Ubuntu (Step-by-Step)

Guide 10-53331 · Updated · Step by step

This guide walks you through installing Vim, the powerful terminal-based text editor, on Ubuntu. You’ll learn the exact commands to run, how to verify the installation, and what to do if something goes wrong. No prior experience with the terminal is needed—just follow the steps in order.

What You’ll Need

  • An Ubuntu system (desktop or server) with an active internet connection.
  • A user account with sudo privileges (administrative rights).
  • Access to a terminal window (Ctrl+Alt+T on desktop, or SSH for remote servers).

Step-by-Step

  1. Open a terminal. On Ubuntu desktop, press Ctrl+Alt+T. If you’re on a server, log in via SSH as usual.
  2. Update your package list. Run sudo apt update. This refreshes the list of available software from Ubuntu’s repositories. Enter your password when prompted (it won’t show as you type).
  3. Install Vim. Run sudo apt install vim -y. The -y flag automatically confirms the installation prompt. Wait for the download and installation to finish—it usually takes less than a minute.
  4. Verify the installation. Run vim --version. You should see output starting with VIM - Vi IMproved and a version number (e.g., 8.2 or 9.0). If you see this, Vim is installed correctly.
  5. Test Vim. Run vim test.txt to open a new file. You’ll enter Vim’s normal mode. Press i to switch to insert mode, type some text, then press Esc to return to normal mode. Type :wq and press Enter to save and quit. Check that the file was created with ls -l test.txt.
  6. Optional: Install Vim’s GUI version (gvim). If you prefer a graphical interface, run sudo apt install vim-gtk3. This adds the gvim command, which opens a windowed editor.

Common Mistakes

  • Forgetting to update first. Running apt install without apt update may install an old version or fail if the package index is stale. Always update first.
  • Typing vim and getting stuck. New users often don’t know how to exit. Press Esc to ensure you’re in normal mode, then type :q! to quit without saving (or :wq to save and quit).
  • Using sudo unnecessarily. You don’t need sudo to edit your own files. Only use sudo vim when editing system files (e.g., in /etc).
  • Installing the wrong package. Ubuntu offers vim (minimal), vim-tiny (very limited), and vim-gtk3 (with GUI). The standard vim package is what most users want.

Tips

  • Learn basic Vim commands. Run vimtutor in the terminal for a 30-minute interactive tutorial that teaches navigation, editing, and saving.
  • Use a configuration file. Create ~/.vimrc to set options like set number (line numbers) and set tabstop=4. This makes Vim much more comfortable.
  • Install plugins. Use a plugin manager like Vundle or vim-plug to add features like file trees, syntax highlighting, and autocomplete. For example, with vim-plug, add Plug 'preservim/nerdtree' to your .vimrc and run :PlugInstall.
  • Check for updates. Vim is actively developed. Periodically run sudo apt update && sudo apt upgrade vim to get the latest version.

Troubleshooting

  • “Package ‘vim’ has no installation candidate” — This usually means your package list is outdated or the universe repository is disabled. Run sudo apt update first. If the problem persists, enable the universe repository with sudo add-apt-repository universe then update again.
  • Permission denied when installing. If you see E: Could not open lock file /var/lib/dpkg/lock, another package manager process is running. Wait a few minutes and try again, or reboot if it’s stuck.
  • Vim opens but looks weird (e.g., arrows print letters). This happens in insert mode. Press Esc to exit insert mode. If arrow keys still don’t work, your terminal may be in a compatibility mode—try vim -u NONE to see if a plugin is causing issues.
  • “vim: command not found” after installation. The installation may have failed silently. Run sudo apt install vim again and watch for error messages. Also check that your PATH includes /usr/bin by running which vim.
  • Vim is very slow on large files. This is normal for syntax highlighting. Disable it temporarily with :syntax off or add set lazyredraw to your .vimrc.

Frequently Asked Questions

Is Vim pre-installed on Ubuntu?

Ubuntu includes vi (the older editor) by default, but not full Vim. Run vim --version to check. If it says “command not found”, you need to install it as described above.

What is the difference between vi and vim?

Vim (Vi IMproved) is a superset of vi with additional features like syntax highlighting, undo levels, and visual mode. On Ubuntu, vi is often a minimal version, so installing Vim is recommended for everyday use.

How do I uninstall Vim?

Run sudo apt remove vim. To also remove configuration files, use sudo apt purge vim. This is useful if you want a clean slate.

Can I use Vim to edit system files?

Yes, but you need root privileges. Use sudo vim /etc/hosts (for example). Be careful—mistakes in system files can break your system.

Why does Vim use so much memory?

Vim is lightweight compared to GUI editors, but it can use more memory if you have many plugins or open large files. Disable unused plugins and avoid opening files larger than a few hundred megabytes.

How do I update Vim to the latest version?

Ubuntu’s repositories may lag behind the latest release. To get the newest Vim, you can add the ppa:jonathonf/vim PPA (run sudo add-apt-repository ppa:jonathonf/vim, then sudo apt update && sudo apt upgrade vim). Alternatively, compile from source, but the PPA is simpler.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →