To gain weight, eat more calories than you expend.
It's that simple. This is basic physics, weight gain and loss is not complicated.