Some exogenous variables (i.e., those outside the bounds of one's skin) contributing to depression: Messed up relationships with other people; the way you were raised; a lack of opportunity to develop emotionally, physically, sexually, and so on; acute stress (you've lost your job, just broke up, and so on); chronic stress (a shithead boss that does little things to annoy you day by day); the stage of life you're in (being a teenager or a recent retiree with no job anymore, for example)
Some endogenous variables (i.e., those within the bounds of one's skin) contributing to depression: genetics -- data indicate certain mental illnesses unfold at certain ages in people independent of external stimulus, indicating a genetic cause (e.g., schizophrenia); your way of coping with stress (blaming yourself, loading up on drugs, whatever); your beliefs (believing you're a worthless piece of shite or some such will cause problems); your nervous system (some people have arousal systems that are wired to have intense reactions and this can contribute to depression); the chemical state of your brain (it is recognized that certain imbalances induce or are otherwise coextensive with depression in many instances)
Obviously, all of these variables interact with one another in a variety of complex ways, in addition to (probably) overlapping to some degree.
Solutions:
(i) Work to improve your relationships with others, or, if you don't have any, establish some.
(ii) Identity the opportunities you are missing out on and formulate a plan to expose yourself to said opportunities. This is broad and depends on your specific situation, but might include spending more time with members of the opposite sex, going back to school to have a better chance in the job market, etc. Take a whole weekend to reflect on your life and why you're unhappy, an activity which will naturally suggest means for rectifying the situation.
(iii) Develop an in-depth stress reduction regime, including a proper exercise and diet, meditation, supplementation, and whatever other activity you have found works to reduce stress
(iv) Get a cognitive behavioral therapy workbook (they publish them as self-help manuals these days) and try out some of its methods for a few months and see if things aren't better. If not, consider more in-depth treatment by a professional. CBT will address issues like irrational thoughts that contribute to depression (e.g., Luberyourman's absurd "your life is predetermined, all of life is about domination" bullshit) and certain behavioral tricks to ameliorate, and ultimately treat, your condition.
(v) Consider medication if your problem has been longstanding and isn't clearly linked to external events in your life.
(vi) Formulate goals -- long-term ones broken down into short-term ones -- and accomplish them on a regular basis. The accretion of accomplished goals recorded for posterity's sake can help one's self esteem, especially since if you're depressed you're probably focusing only on negative things, a bias a proper goal planning and recording program will help eliminate
(vii) Stay active: it's harder to be depressed when you are earning a pilot's license, riding a horse, surfing, learning a new language, exploring an ancient Buddhist temple, mountain biking, skydiving, fishing, proving a tough theorem, French corkscrewing a Brazilian belly dancer, reading an awesome sc-fi novel or work of literature, etc. rather than sitting at home sulking, even if at first you don't enjoy the activity to its fullest because you are, after all, depressed.