Gaining weight will come from a variety of lifestyle factors, including your diet, exercise, genetics, sleep, etc. Perhaps most importantly (nutritionally speaking), you have to consume enough calories and protein to support your weight gain.
You will want to eat in a slight calorie surplus. This means that you are eating more calories than your body needs to maintain its weight. Just a couple or a few hundred extra calories per day on top of what you need to maintain your weight should do the trick for a slow and gradual weight gain.
Along with calories, protein is also very important. Consuming enough protein will support your weight gain and allow more of the gain to be lean mass. Protein is essential for building and maintaining muscle, as well as playing a role in other crucial processes in the body. While you don't want to consume way too much protein, you want to eat enough of it to meet your increased needs as you are exercising and trying to gain weight.
Even though diet is the main priority, your exercise is super important too! We recommend including strength training and cardio, at least 3-4 days a week. They both offer great benefits, and neither one should be neglected. Although exercise uses calories, it's great for building and recovering muscle, keeping your heart healthy, strengthening bones and joints, and increasing your appetite.