Confidence comes from understanding that you are doing well, and doing a good enough job. It comes with experience and understanding. You can fake it to a degree, but as soon as you run into a complication, fake confidence normally falls away.
Confidence is normally passive. As you learn to respect yourself, you'll gain confidence, but it's also circumstantial.
For example, if you're learning something, you don't need the confidence in what you're learning, you need the confidence in your ability to learn. This common mistake leads to a lot of newbies either trying to jump ahead, or being scared to try new things.
If you have an instructor, if you think they're wrong, try to follow their advice and see how it feels, or ask them about why you think they're wrong. If they think you're ready for something and you don't, trust them and try it.
If you're learning on your own, don't be afraid to try new things in a safe environment. Ask people who might be able to answer questions and test their replies. You're discovering a new space, you won't have confidence in it off the bat, but you want to have the confidence to ask questions and find answers.
General confidence is also something you have to 'study' for. You don't study confidence itself, but, you want to study things like how people respond to you in certain situations. Knowing you are allowed to make mistakes in social situations will teach you to be more generally confident. Mistakes are allowed, just learn from them.