The best way to write dialogue is to listen to the conversations around you and practice re-writing them. Dialogue has to sound realistic but, on the page, you can cut all the boring bits and get right to the most important parts, meaning it isn’t actually realistic at all. None of the ‘Hey, how are you?’ stuff needs to be in there.
To practice, rewrite the last conversation you had/or the last conversation you overheard. Try and do it word for word, no matter how dull it was. Now re-write it but cut to the chase – delete all the uninteresting parts and leave yourself with a few lines of sparkling back and forth.