First, make sure that you have cmake and llvm installed, since YouCompleteMe needs to be compiled:
$ sudo apt-get install cmake llvm
For Windows, you can get cmake from https://cmake.org/download and llvm from https://releases.llvm.org/download.html. YouCompleteMe requires Vim to be compiled with +python. You can check whether your Vim was compiled with Python support by running vim --version | grep python. If you see -python, you'll have to recompile your Vim with Python support.
If you're using vim-plug, add the following to .vimrc:
let g:plug_timeout = 300 " Increase vim-plug timeout for YouCompleteMe.
Plug 'Valloric/YouCompleteMe', { 'do': './install.py' }
Save the file and execute it:
:source $MYVIMRC | PlugInstall
Depending on how fast your machine is, this might take a while. You will be greeted by a successful installation screen:
If you're running into an error such as c++: internal compiler error: Killed (program cc1plus), then your machine likely doesn't have enough memory to complete the operation. On Linux, you can perform a swap to increase the available space:
$ sudo dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
$ sudo mkswap /var/swap.img
$ sudo swapon /var/swap.img
$ sudo dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
$ sudo mkswap /var/swap.img
$ sudo swapon /var/swap.img