sudo apt update
sudo apt dist-upgrade
For Intel CPU :
sudo apt install intel-microcode
For AMD CPU :
sudo apt install amd64-microcode
After that, reboot your Ubuntu box.
That's all! See you.
Update on JAN 24, 2018
Since Linux creator Linus Torvalds disagrees to install Intel's patches for Spectre, the Intel microcode is patched back to the previous version. You are not required to uninstall it. You just update and it will patch it back to the previous version. Please see The Hacker News for details.
sudo apt update
sudo apt dist-upgrade