Facebook said Tuesday it was buying Oculus, a specialist in virtual reality technology, for about $2 billion in cash and shares.

Facebook said it would build on Oculus’ technology, including a virtual reality headset aimed at gamers, seeking to use it in other areas such as communications, education, and entertainment.