I have tried to install kodi by typing
sudo apt-get install open-elec but it says there is no such thing.
How do I install it by terminal?
Because you should have just asked for what you wanted:
apt-get install kodi
For future reference,
apt has a search feature:
apt-cache search kodi
This will return a list of packages with "kodi" in their name or short description.
You can also just deploy the preconfigured openElec Card
Use OSMC it's based on Kodi and it's pretty https://osmc.tv/