“You have to learn to share.”
Your son is playing with another child his age. He has a toy which the other child wants to play with. He won't give the toy to the other child, so you tell him this.
You have to learn to share.
This is a very straightforward way to give someone advice. You use this phrase when you definitely know more about something than the people who are listening:
A: I've never eaten that before. Do you eat it raw?
B: No, you have to cook it.
You can also use "You have to ___" when you're excited about something and you want to share it:
You have to try this! It's delicious!
If you use "You have to ___" to share an opinion, you might come across as rude. For example, don't use this phrase when giving friends advice about their relationships, job, etc.
To "share" means to let other people use something that's yours or that you're using. Usually, when we use the word "share", we follow it with two pieces of information: what you shared, and who you shared it with.
She shared her toys with her brother.
But you can also just use "share" like this:
Let's share it.
Or even like this:
We have to share.
In the last example, the thing that you're sharing and who you're sharing it with must be understood based on the situation.