Linux and Vim alike are not your everyday bread like Windows and MacOS. While it truly is becoming easier to transition to Linux from an easier operating system like Windows with the emergence of beginner-friendly desktops like Zorin OS, there’s still one thing that’ll never get easier. And for several good reasons. It’s the Linux Command Line – a terror for those who barely know what a terminal does. It was not long ago before our ancestral computer people had no idea about a GUI, like most of us do nowadays. So it makes sense why the terminal meant a lot in the early days. Linux is old, and you should admit that.
Linux is like a mix of both worlds (at least as of now). A lot of modern graphical interfaces in Linux try to take away as much of the terminal as possible from a beginner’s visibility range when they boot Linux for the first time. However, the roots of Linux won’t always favor this new beginnerness (there’s no such English word, though). A lot of it still requires direct interaction to the terminal, in which case, you’re outta luck, pal.
For now, let’s not bother about all the problems that one could encounter if they’re not familiar with the Linux Command Line, keep aside Bourne Again Shell. If your only concern is to stop seeing this message “Bourne Again Shell: vim: command not found”, you might as well find luck here. Also, for existing users of Vim, this problem isn’t uncommon at all – not because you don’t know Bourne Again Shell, but because you’re using Vim the wrong way. Actually, you’re not using Vim in the first place.
Do you know what Vim is?
Vim is a text editor. That’s the simplest way I could tell you. Vim is used to edit files that contain text, or code, or just about anything that contains ASCII characters. It is primarily designed to edit text at the speed of thought (that’s how people like to refer to it). It is not meant to be an IDE like VS Code, or Sublime Text, but it can also be used as one with the help of plugins. Pretty straight forward.
Stop pasting from the Web
Yes. You heard it right. Pasting directly from the web a string of code without proper knowledge may not only give you errors like this, but can be malicious at times as well. So stop doing it before you realize how wrong things could go. Just like it isn’t good to scan a random QR code on the streets, it ain’t a good idea to paste random code from the web, unless you really know what you’re doing.
The “bourne again shell: vim: command not found” could be a common error while trying to setup a software in Linux as a lot of ‘em require a code editor to work in the background to edit files that are being processed. Sometimes, certain scripts tend to use Vim, as it is pretty much installed in most Linux operating systems at present. If you try to run such a command in Windows Command prompt, or simply a machine where Vim is not installed, you’d definitely get this message.
Is it Vim or is it Vi?
Besides the common phenomenon of people pasting text from the web, there’s also another possibility for you to see this error. Basically, there are two closely related softwares, Vim and Vi Text Editor. Vim is like the successor to the old Vi, with more enhanced features. However, a lot of systems still tend to include Vi by default instead of Vim. In such cases, it is possible to confuse the Enhanced Vim with the Vi Editor, as once you have Vim installed, simply vi in your terminal will redirect to the Enhanced Vim, whether or not you have the old Vi installed.
How to install Vim
Installing Vim is not hard in any means, unless it’s Windows (more on that later). Most Linux distributions have the Vim package in their repository, so you don’t have to worry about needing to add extra ones. Vim is not limited to Linux, Windows and MacOS, but can also be installed on Android and iOS devices, using terminal emulators like Termux and iSH.
For now, I’m guessing you’re probably doing this from a Linux, Windows, or a MacOS. There are also operating systems like openBSD. If you ask me, I’d definitely give you that Vim is one of the most widely available text editors across so many different systems. Anyways, it’s time to install Vim. I’ll be listing the common ways of installing Vim in your machine. If you system isn’t listed here, you could find luck trying to search for a way to install it in your system (unless you’re using something no one has knowledge of).
$ sudo pacman -S vim
$ sudo apt install vim
$ sudo dnf install Vim
FreeBSD (it ain’t Linux, though):
$ pkg install vim
There are several ways you could install Vim in MacOS. Some prefer the graphical version of it, formerly, Gvim, but I’ll go for the terminal on this one. You can check out other tutorials online to see if you’d like to install it in some other way. I’m using HomeBrew for the following command to be executed:
$ brew install vim
Using Vim from Windows is a bit of a hassle. Firstly, visit the official vim.org website of Vim, and head to the Download section available at the left side, with a green background for you to easily find it. At the very top you’d find the download options for MS-Windows (stated as the most popular). The first link will lead you to a github page, where you could download the required version of Vim. The next is just a graphical version of vim, gvim, with no other dependencies included in that package. The best one that I’d recommend you is the last option, that says “standard self-installing executable”.
Click on that and download Vim. Once done, install the program like you normally would with any other program. Afterwards, you’ll find two different pieces of executables with many other dependencies stored in the bin directory – one of ‘em is vim, that’ll open up in the Windows command prompt, and the other being gvim, which will fire up in its own, graphical window.
Incomplete Vim installation from source
This is yet another possibility for you to see the error message. If you’ve tried to install Vim by building it from the source files, it is very much possible the environment variables are not properly set. In this case, you’ll first want to locate the place where you had installed Vim, if you had defined a separate location while running make. In Linux, you can add the directory to the installation to the global PATH variable in Linux, like this:
Make sure to replace the from “<” to “>“, with the actual path instead of just copy-pasting it in your terminal. You might as well want to include this in your .bashrc file. Otherwise, you may need to use this command everytime in your terminal after a restart. It is actually just a configuration file for the bourne again shell, located in your home directory.
Therefore, it’s best to add this line to your .bashrc file, if the bourne again shell is what you’re using. If you’re using any other shell, check out how to add commands to the shell startup script.
Properly Install Vim from Source
As an extra, I’ll tell you how to build Vim from source properly, if you’re unable to set it up yourself. A lot of old systems don’t include the latest version of Vim, so it might help you get the best out of it.
First, pull the source code from github using the following command. Make sure to have the git package installed in your system:
$ git clone https://github.com/vim/vim.git
Now enter the src sub-directory by using:
$ cd src
Run make to compile the program:
Lastly, Install the program so that it can be made accessible throughout the system and can be run directly from the terminal by using the vim command. To Install it, use the following command in your terminal:
$ sudo make install
If you haven’t successfully surpassed the error message by now, then close everything, shut down your pc, and have a good sleep. Yes, even if it’s early in the morning. But I’m quite hopeful you won’t need to. Because most people have at least one of the mentioned problems. There aren’t any other ways you could come around the issue. Therefore, stop blaming Vim. It’s not Vim’s fault, fella.