Compiling and Installing Vim from Source on Ubuntu
First, remove any pre-installed Vim packages from your Ubuntu system to avoid conflicts:
sudo apt-get remove --purge vim vim-runtime vim-tiny vim-common
Next, clone the latest Vim source code to your home directory:
cd ~ && git clone https://github.com/vim/vim.git
Install all required build dependencies and development libraries to enable full language and feature support:
sudo apt-get install libncurses5-dev python-dev python3-dev ruby-dev liblua5.3-dev libperl-dev git
Navigate to the source build directory, clean any previous build artifacts, configure the build with your desired features, compile, and install:
cd vim/src
# Clean up old build data if you have compiled Vim here before
make distclean
./configure \
--prefix=/usr/local \
--with-features=huge \
--enable-multibyte \
--enable-cscope \
--enable-python3interp=yes \
--with-python3-config-dir=$(python3-config --configdir) \
--enable-rubyinterp=yes \
--enable-perlinterp=yes \
--enable-luainterp=yes
make
sudo make install
Update system alternatives to set your newly compiled Vim as the default editor for both vi and editor commands:
sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim 1
sudo update-alternatives --set editor /usr/local/bin/vim
sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1
sudo update-alternatives --set vi /usr/local/bin/vim