Most bikes will have a dedicated cabe routing guide, however if you don't have one of those, a quick little hack is to use a zip tie and endcap.
Snip the end cap in half. Thread the zip ties through the end cap, wrap it around the cable, back through the end cap, and then tighten the zip tie around the frame. Then snip the end of. This keeps the cable off the frame which prevents rubbing.