How can I put on weight?

I am extremely thin/skinny guy . ( 5'10" and 55 kg )

I am told my ideal weight is 80 kg .

How can I increase my weight ? Is it possible to do that ? If yes, how long would it take ?

I went to gym though it made me loose 3 kg , so I stopped it .

Can you help me with that ?

Updates
+1 y
I am vegetarian .
Updates
+1 y
I had seeked advice from a physical trainer but he proved unbeneficial . I worked out in the gym for 20-25 days which cost me 3 kgs ( I was 58 kg before and now I am 55 kg ). I didn't want any further loss in my weight , so I stopped going to the gym . Also, when I got in the gym , my diet started reducing ( in the sense - I didn't get hungry ) which was pretty unusual as I've heard that you start to get more hungrier when you hit the gym ,lol .
How can I put on weight?
Post Opinion