How to Install Neovim on Ubuntu 22.04 or 20.04

Discover Neovim, a state-of-the-art text editor built on the foundation of Vim, offering a free and open-source solution tailored for maximum usability and extensibility. Neovim emphasizes seamless maintenance and actively encourages contributions from a diverse community of developers. The platform leverages application programming interfaces (APIs) and plugins to deliver a feature-rich and versatile text editing experience.

Neovim’s vision revolves around fostering a collaborative environment, simplifying maintenance, and enabling the creation of powerful plugins and interfaces. By focusing on these objectives, Neovim aims to improve Vim’s already impressive capabilities, making it an even more valuable tool for developers.

Neovim vs. Vim: Key Advantages of Neovim

  • Simplified maintenance and promotion of community contributions
  • Collaborative environment with distributed workload among developers
  • Effortless integration of modern user interfaces without altering the core source
  • Superior extensibility via an advanced plugin architecture

To gain deeper insights into Neovim’s vision and objectives, explore the Vision section on the Neovim website.

This comprehensive tutorial will walk you through installing Neovim on Ubuntu 22.04 LTS Jammy Jellyfish or Ubuntu 20.04 Focal Fossa using various methods. These include the Ubuntu default repository, the Neovim team’s LaunchPAD PPA, and third-party managers like Snapcraft or Flatpak, all accessible through the command line terminal.

Update Ubuntu

Before proceeding with the installation, updating your Ubuntu system to ensure optimal performance and compatibility is crucial. To update your system, execute the following command in the terminal:

sudo apt update && sudo apt upgrade

This command updates your package list and installs any available updates.

Method 1: Install Neovim with Ubuntu Repository

For many users, the most straightforward and convenient method to install Neovim is through the standard Jammy Jellyfish repository. To install this version, run the following command:

sudo apt install neovim

Please note that this method installs the version of Neovim available in the official Ubuntu repository, which may not be the most recent version. For users seeking the latest updates and features, consider using one of the Neovim team’s PPA versions as an alternative installation method.

Method 2: Install Neovim with Neovim Team PPA

Begin by ensuring your system has the necessary packages installed. Execute the following command to install them:

sudo apt install ca-certificates apt-transport-https software-properties-common lsb-release -y

This command installs the required packages needed for the import process.

Next, initialize the GPG keyring and create the necessary directories for the import process with the following command:

sudo gpg --list-keys

Upon executing this command, the required directories will be created:

gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created

To add the GPG key for the Neovim PPA to the /usr/share/keyrings/ directory, run the following command:

sudo gpg --no-default-keyring --keyring /usr/share/keyrings/neovim-ppa.gpg --keyserver keyserver.ubuntu.com --recv-keys 9DBB0BE9366964F134855E2255F96FCF8231B6DD

This command adds the GPG key to the keyring directory, ensuring it can only be used for the Neovim installation.

You should see an output similar to this:

gpg: keybox '/usr/share/keyrings/neovim-ppa.gpg' created
gpg: key 55F96FCF8231B6DD: public key "Launchpad PPA for Neovim PPA Team" imported
gpg: Total number processed: 1
gpg:               imported: 1

With the GPG key imported, the next step is to add the Neovim PPA to your system. Use the following command:

*Note: Only one version can be installed simultaneously. If you import both the stable and unstable versions, the unstable version will be installed as it is the most recent version.

Import Neovim stable PPA:

echo "deb [signed-by=/usr/share/keyrings/neovim-ppa.gpg] https://ppa.launchpadcontent.net/neovim-ppa/stable/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/neovim-ppa-stable.list

Import Neovim unstable (nightly) PPA:

echo "deb [signed-by=/usr/share/keyrings/neovim-ppa.gpg] https://ppa.launchpadcontent.net/neovim-ppa/unstable/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/neovim-ppa-unstable.list

This command adds the Neovim PPA, allowing you to install the Neovim package from the repository.

Next, update your package index to include the newly added PPA:

sudo apt update

Now, you can proceed to install Neovim using the following command:

sudo apt install neovim

Upon completion, Neovim will be installed on your system using the Neovim Team PPA. You can also verify that the PPA version is installed by running the following command:

apt-cache policy neovim

Example output indicating the Neovim PPA as the installed version on Ubuntu; for this guide, the unstable version was used:

Method 3: Install Neovim with Snapcraft

The third option for installing Neovim is using the Snapcraft package manager. Snap should already be installed on your Ubuntu desktop unless it has been previously removed.

While Snapcraft is not as popular as Flatpak, it is developed by the same team behind Ubuntu. Flatpak has a broader adoption rate among various Linux distributions, resulting in package maintainers updating Flatpak versions more quickly than Snapcraft. However, this depends on the specific package maintainer.

If you have removed snapd from your system, reinstall it using the following command:

sudo apt install snapd

Some packages require classic snap support. To enable this, create a symlink with the following command for optimal snap compatibility:

sudo ln -s /var/lib/snapd/snap /snap

Install the core files to prevent conflicts:

sudo snap install core

Finally, install the snap version of Neovim:

sudo snap install nvim --classic

With these steps completed, Neovim is now installed on your system using the Snapcraft package manager.

Method 4: Install Neovim with Flatpak and Flathub

An alternative method for installing Neovim is Flatpak, a versatile package management system that provides a sandboxed application environment. To install Neovim via Flatpak, you must add the Flathub repository containing the Neovim package.

Note: If Flatpak isn’t installed on your system, please refer to How to Install Flatpak on Ubuntu with the Flatpak Team Official LaunchPAD PPA. This guide offers instructions for obtaining the latest supported version using the Flatpak Team Official LaunchPAD PPA.

Begin by opening the terminal and entering the following command to integrate the Flathub repository:

sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Now, run the Neovim installation using the following flatpak command:

flatpak install flathub io.neovim.nvim

With these steps completed, Neovim is installed on your system using the Flatpak and Flathub package manager.

How to Launch Neovim

There are several methods for launching Neovim, depending on your installation method and preference. Here are the different ways to start Neovim on your system:

Standard Installation: If you installed Neovim using the default repository, PPA, or built it from source, launch Neovim by entering the following command in your terminal:

neovim

Snapcraft: If you installed Neovim using Snapcraft, launch it from the terminal with the following command:

sudo snap run neovim

Flatpak: If you installed Neovim using Flatpak, run the following command in the terminal:

flatpak run io.neovim.nvim

Desktop Application: For desktop users, locate the Neovim application icon by navigating to Activities > Show Applications > Neovim. You can also add Neovim to your favorites for easy access.

Example of Neovim application icon on Ubuntu Desktop:

Once you have Neovim installed and opened for the first time, you might want to familiarize yourself with its features and make some initial customizations. Here are some tips to help you get started:

  • Learn the basics: Neovim is a modal editor, which means it has different modes for inserting text, navigating, and editing. Familiarize yourself with the basic commands and modes, such as normal, insert, and visual mode. Type vimtutor in your terminal to access an interactive tutorial that covers essential commands and concepts.
  • Customize your configuration: Neovim’s settings are stored in a configuration file called init.vim. Create this file in the ~/.config/nvim/ directory by running the following command in the terminal:
mkdir -p ~/.config/nvim && touch ~/.config/nvim/init.vim

Open the file using nvim ~/.config/nvim/init.vim and start customizing your settings, such as color schemes, key mappings, and plugins.

  • Explore color schemes: Customize your editor’s appearance with different color schemes. You can find various color schemes online. Download the desired color scheme, and place it in the ~/.config/nvim/colors/ directory, and add the following line to your init.vim file:
colorscheme your_color_scheme_name
  • Learn key mappings: Neovim allows you to create custom key mappings to improve your workflow. Add key mappings to your init.vim file using the following format:
nnoremap key_sequence action

For example, to map jk to the Escape key in insert mode, add the following line:

inoremap jk <Esc>
  • Documentation: Neovim has extensive documentation built-in. To access it, type :help followed by the topic you are interested in. For example, type :help navigation to learn about navigating within files.

Following these tips, you can customize Neovim to suit your preferences and improve your productivity.

Example of Neovim open on your Ubuntu Desktop:

Additional Tips

How to Update Neovim on Ubuntu

To ensure that you are using the latest version of Neovim, it’s crucial to check for updates regularly. While update notifications may appear automatically, verifying updates’ availability manually is good practice. Depending on your installation method, use one of the following commands in the terminal to check and apply updates for Neovim:

For APT Method:

To update Neovim installed via the APT method, first update the package list and then upgrade the packages:

sudo apt update && sudo apt upgrade

For Flatpak Method:

To update Neovim installed via Flatpak, execute the following command:

flatpak update

For Snap Method:

To update Neovim installed via Snap, run the following command:

sudo snap refresh

By regularly updating Neovim, you can benefit from the latest features, improvements, and bug fixes, ensuring a smooth and efficient experience.

How to Remove (Uninstall) Neovim on Ubuntu

If you no longer need Neovim on your system, follow the instructions below to uninstall it, depending on the original installation method. Additionally, these steps will help you clean up any leftover files and data to maintain a clutter-free system.

For APT Remove Method:

To uninstall Neovim installed via the APT method, execute the following command:

sudo apt remove neovim

To clean up any unused packages from Neovim and other applications, run the autoremove command. This process is generally safe and helps prevent system bloat:

sudo apt autoremove

If you installed Neovim using one of the PPAs, remove them with these commands:

  • Remove Neovim Stable PPA:
sudo rm /etc/apt/sources.list.d/neovim-ppa-stable.list
  • Remove Neovim Unstable PPA:
sudo rm /etc/apt/sources.list.d/neovim-ppa-unstable.list

For Flatpak Remove Method:

To uninstall Neovim installed via Flatpak, run the following command:

flatpak remove  --delete-data io.neovim.nvim -y

Next, execute the following command to clean up any leftover files, similar to the autoremove command used for the APT remove method:

flatpak remove --unused

For Snapcraft Remove Method:

To uninstall Neovim installed via Snapcraft, use the following command:

sudo snap remove --purge neovim

Conclusion

This guide has covered installing Neovim on Ubuntu using various methods, including the default Ubuntu repository, Neovim Team PPA, Snapcraft, and Flatpak. Each method has unique advantages, allowing users to select the most suitable approach for their needs. Furthermore, we have provided essential tips for first-time Neovim users, including basic customizations and initial setup guidance. Lastly, the guide outlines the steps for updating and uninstalling Neovim on Ubuntu, ensuring users can keep their system up-to-date and free from clutter. By following this comprehensive guide, users can seamlessly integrate Neovim into their workflow and enhance their text editing experience on Ubuntu.

Additional Resources

To further enhance your experience with Neovim and expand your knowledge, the following resources are highly recommended:

  • Neovim Official Website: https://neovim.io/ Visit the official Neovim website for the latest news, updates, and comprehensive documentation on using and configuring the text editor.
  • Neovim GitHub Repository: https://github.com/neovim/neovim Explore the Neovim GitHub repository to access the source code, report issues, contribute to the project, or browse through the available plugins.
  • Neovim Plugins: https://vimawesome.com/ Vim Awesome is a directory of Vim plugins sourced from GitHub, Vim.org, and user submissions. Many of these plugins are compatible with Neovim, allowing you to extend the functionality of your text editor.
  • Neovim Subreddit: https://www.reddit.com/r/neovim/ Join the Neovim community on Reddit to discuss tips, tricks, plugins, and any questions about using and configuring Neovim. This is an excellent place to learn from other users and share your experiences.
  • Documentation: https://neovim.io/doc The official Neovim documentation provides a comprehensive guide to understanding and using Neovim’s features and commands. It is an essential resource for both new and experienced users.
  • User Manual: https://neovim.io/doc/user The Neovim user manual explains the editor’s features, usage, and configuration. This is an excellent starting point for learning how to customize and optimize your Neovim experience.
  • Neovim Features: https://neovim.io/doc/user/nvim.html This webpage overviews Neovim’s unique features and improvements over the traditional Vim editor. By familiarizing yourself with these enhancements, you can take full advantage of Neovim’s capabilities.
  • Neovim Team PPA: https://launchpad.net/~neovim-ppa The Neovim Team’s Personal Package Archive (PPA) on Launchpad offers a convenient way to install the latest stable or unstable versions of Neovim on Ubuntu-based systems.
  • Neovim Snapcraft: https://snapcraft.io/nvim The official Neovim Snapcraft page provides information about the Neovim snap package, installation instructions, and user reviews. This resource is useful for those interested in installing Neovim using the Snap package manager.
  • Neovim Flathub: https://flathub.org/apps/details/io.neovim.nvim The Neovim Flathub page offers details about the Neovim Flatpak package, installation guidance, and user feedback. This page is particularly helpful for users who prefer to install Neovim via the Flatpak package manager.

Share to...