How to install LXD container under KVM or Xen virtual machine

Originally published at: https://www.cyberciti.biz/faq/how-to-install-lxd-container-under-kvm-or-xen-virtual-machine/

For security and ease of admin, I want to install LXD on my cloud server either powered by XEN or KVM. How do I install LXD on Ubuntu Linux server powered by KVM virtualization technology?