According to a recent survey, people contribute to open source to improve something they already use, with “the enjoyment of learning and fulfilling a need for creative or enjoyable work” coming after. Money was at the bottom, probably because it’s hard to make money on open source and relatively easy to make money doing similar work for a company. These hold true in my experience—and generally for me, personally, although I haven’t done much open source work.
Many developers spend hours working with computers and want the experience to be as seamless and optimized as possible. When a tool they’re using isn’t behaving exactly how they want (such as an edge-case bug or a desired feature), they have the ability to directly improve their life (and others’) in a small way by improving this tool. And any contribution they make likely benefits many users, some of whom lack the knowledge or motivation to do it themselves.
The other two motivations are similar to each other and are very pure, in a way that an idealist or zealot like Richard Stallman would approve. It also refutes the notion that people will only write software if they’re paid for it, exemplified by Bill Gates and his fight over Altair BASIC and his “Open Letter to Hobbyists.” Many open-source writers are also professionals who make large salaries working day jobs, which takes care of their financial needs but may leave them wanting to work on what they want, away from strict deadlines and management structures. Open source offers the perfect solution to this, because each individual has almost complete freedom to pick which projects and tasks they work on. The freedom to work on what they want, when they want is a stark contrast from a typical day job, and which makes it fulfilling. A similar reasoning applies for students who have homework and projects that they may not enjoy—open source is a respite from this.
Lack of time and motivation are two major factors that keep people away from open source that there really is no way to prevent. Burnout can be prevented by taking breaks from contributing when things get too stressful and spending a healthy amount of time on it, and encouraging others to do the same. But another problem that drives people away (and is not inevitable or inherent) is a toxic community or leadership. This can be in the form of a project that’s too intimidating to let beginners get their feet wet, or a project that drives away longstanding contributors over disagreements on the project’s direction, for example.
The most important thing a healthy community needs is good leadership, either one person or a group of people, although neither is inherently better than the other. A single leader (like a benevolent dictator for life) can become difficult to work with (like Linus Torvalds on Linux) and refuse to see alternate project directions other than their own, which is bad for the community when other members feel undervalued or ignored. Leadership by committee can be problematic by both the problems listed previously for an individual—a group can become just as detached as a person—and internal squabbles about the best solution. But no matter who the leader or leaders are, a good community is one where every member gets to fairly contribute as appropriate for their knowledge or experience.