Bugs simply make instruments easier to read with a very quick glance.
If I need to steer exactly 162 degrees, which is easier? To read where the needle is pointing or just see if the needle is pointing to the bug which I manually set to 162 degrees?
The bugs are set by rotating knobs on the gauges. Here, the heading bug knob is in the lower right corner.
The way I often use it is to turn onto the next heading required according to my plan, then set the bug to that heading so that I can simply glance at the needle (still pointing to the bug, good) to keep me on course.
If ATC gives you a "next heading", you will read back the instruction, then you can set the bug to that next heading so that a), you don't forget it and need to call back and b) can simply turn onto the bug when it's time to turn.
Set it to the departure runway heading on take off. To "fly runway heading", just keep the bug at the top of the gauge.
On arrival, set it to the landing runway heading.
As a "gross error" check. You would not believe how many inexperienced pilots set off in entirely the wrong direction. As well as setting the heading bug to "first leg of the plan", you check this along with "and the road should be on my left with the river on my right".
On some simple autopilot systems, the autopilot follows the altitude and heading bugs rather than having controls for these settings on the autopilot itself.