Keep your dialogue tags simple. "Said/says" is what you want 90% of the time, with the occasional "ask/asked." Every once in a while, there might be something else, but you mostly want your dialogue tags to feel invisible. Keep it simple.
Be careful of writing in a dialect (or accent) -- it usually comes off as contrived and trips up the reader.
Try and get into your characters head. The more you are,the easier it is to write for them. And exorcize I like to do before writing for any new characters is write a series of questions, both personal and not, and answer them as your character. It'll give you some practice
Avoid cuss words, or common slang as much as you can. Not for modesty's sake, but because words like that can end up being crutch words which inhibit an opportunity for good writing.
For instance, "That fucking fuck fucked that fuck." while unimaginative, is a grammatically correct sentence.
As much as I am loathe to admit it, for a good example of writing dialogue, at least in modern language, check out the pesterlogs of the popular webcomic Homestuck ([link]). It is entirely dialogue between characters with differing personalities, and you don't need to know the context to pick up on the nuances of their speech (though some are more obvious than others).
If you want to emphasize that a certain character has an accent, write some words out in a deliberately exaggerated fashion. As Badgercheese1994 suggested, try adding accents. Doing this will enrich your story, as I find when a show or movie has even only one foreign person, it has a more refined flow to it, instead of the same nationality, same race, same skin color, etc. As long as they're portrayed in a respectful manner, of course. For example, say you have a character who's imitating a Swedish accent, the dialogue you'd write for him or her will be like:
"Caaaaammmmm aaaaawwwwwnnnn, getcher assignments in on time!" <- I think it would be more engaging to the viewer than simply writing:
The teacher told her students in a thick Swedish accent, "Come on, get your assignments in on time!"
I mean absolutely no disrespect for Swedish people. I simply used the Swedish example, mostly because I couldn't think of another accent to ustilize.
However, in general, listen to foreign people's accents. Or, if you don't wish to use foreigners, or you fear there are too many, try to balance it out with an important scene with someone who speaks overally well. However, in this scene, their speech is incomprehensible, even by those who are closest to them. Example:
Bob and Alice have broken up. Alice tells everything to her grandmother. Alice is very heartbroken, as Bob cheated on her. Alice cries out loud:
"Graandmhaaahwhwhwa! Bwhaaaahhhb is a jshseerark! Why'd he have to shcrew awup? I trawww- TRAWSTED HIM!" <- Normally, I wouldn't advocate deliberately misspelling words in dialogue. However, I think this is the exception to the rule - while the character is emotional, exaggerate slightly alternate the spelling to match just how upset or excited the character is. Add a few word cuts, such as what I did with "Trust". It'll make it so real, the reader will feel the realism of the emotion.
Here's what Alice is trying to be emotionally strong enough to say in the scene: "Grandma! Bob is a jerk! Why'd he have to screw up? I trusted him!" <- I figure it to be difficult to pass this into the story and make it realistic. The only way one could use this form instead of the other is by describing what is happening to Alice. What are the physical things she's experiencing? What does she feel her heart doing? I find the first example of Alice's dialogue is more appropriate for those who have a hard time intergrating the emotional realism, while this example is more appropriate for when the writer is talented to describe everything that is happening.
I'll be happy to offer more tips or examples, if you wish. I like to help out as much as I can.
Each character should have their own unique voice. Perhaps one character tends to overuse a certain word or phrase, or perhaps another tends to trail off. One could be very flirty and witty, and another could be succinct and blunt.
Your characters should disagree with each other and have different opinions on subjects. This does not mean they need to fight, just that they should each have their own opinions based on their experiences.
Listen to people you know talk to each other, especially those who speak in interesting ways. Keep a notebook with you and jot down some interesting things people say.
Generally gender, upbringing, age, historical era (or approximation) and personality should be taken into account with character and their dialogue.
Read the dialogue aloud, or even with a partner, see how the conversation flows and if it really sounds true to the character. read the conversation backwards, does it make sense and the character sound genuine in response.
Little tics, do your characters do or say anything that makes them familiar to you or the reader? it could be interjecting casual words like 'well', 'so,' 'like', and 'right' it could be small changes in grammar improvement or regression, it could even be something they do rather than say. Do they tug at their clothes when they're nervous, run their hands through their hair, shuffle their feet when they're excited, do they smirk when they're being an ass?
You already got a lot of great advice, to which I would add: don't ALWAYS be clever. Sometimes? Sure. But if you put oh-so-precious dialogue into every person's mouth, they become obvious mouthpieces for you. Try, instead, to remember that people don't always get the point across comfortably, or may misunderstand each other. Ted Sturgeon had a great story who key scene hinged on someone mishearing the emphasis, and becoming furious (instead of "you DID?" he thinks he hears, "YOU did?" and life changes forever). So: my point is: write clumsily sometimes, to prove they are human.
I think most of what could be said has already been said:
What would people actually say? Think about a situation and how real people would talk about it. Read your work aloud. Does it sound natural to you? If not, you may need to tweak something. (It's also helpful if you can find someone to read the dialogue with you: it may seem more like a real situation and help you pick out things that sound awkward).
I'd say all of the stuff everyone's posted about character, and also attention to what the conversation is about. Have they just met? Are they old friends? Do they trust each other? Does one want something from the other? If they do, is the other willing to give it? Or are they simply talking to hear the sound of their own voice?
Listen to real people, and how the way they talk reflects their personalities. A lot of this thing is observation. For characters who come from different countries to me, I often youtube actors or musicians giving interviews so I can listen to the way they talk.
Think about how real people talk, and then take out all the ums, uhs, hesitations, backfillings, and so on that makes for tedious reading.
There's no shortcut. This takes attention and sensitivity, and matching speech with the character's personality based on how you know such people are. A boisterous, outgoing person will speak differently from a diffident, withdrawn person. A boisterous, outgoing person who's easygoing and happy will speak differently from a boisterous, outgoing person who's irritable and sarcastic.