If a friend has a digital game on Xbox you want to play, you don't need to buy an extra copy. You can play theirs on your console with gameshare.
If you are looking to share an Xbox Series X/S with someone and need to set up another account, there is one main way to do so. This will likely be most common for a family group sharing the same ...