Throughout the development of programming itself which came first: open sourced or closed source? Which was more popular? Or did one come after the other?
Early on (long before personal computers) software was not seen as a product of its own, but a part of the computer. So the software was distributed without extra costs with the computer. Many of the purchasers of computers (often universities or scientific facilities) changed the distributed software and added their own programs. All this was practically open source, without the concept existing and no one ever really thought about it.
Later on some companies learned that they could sell software as a product of its own. Closed source software emerged. As a reaction to this new phenomenon of closed source, Richard Stallman started to think about other ways and eventually defined free software. Open Source was a term later coined, but mostly had the same features as free software, so that I see them mostly synonymous.
So, to answer which was first you have to decide if you count early software as open source. Following today's standards it wasn't, because it wasn't licensed. But in practice it was used the same way as open source is today.
Codified free / open source development dates back to the publications of the BSD and GPL licenses; Wikipedia dates BSD to 1988 (although the first properly free version of BSD, 4.3BSD, was released in 1989), and the GPL v1 was published in 1989. Before that, there were freely-developed packages; TeX dates back to 1978 and is known to be FLOSS since at least 1986.
Commercial software is older than that, so closed source development is older than codified free / open source.
Looking back further than that would involve dating the first non-shared software development, and the first shared software development; early computers were purchased for bespoke setups, and the software run on them was closed source, so there again closed source came earlier.
Arguably, open source came first via Ada Lovelace around 1850.
While translating an article on Babbage's Computation Engine, she made the leap of realizing that it could be programmed to solve more than a single dedicated problem.
Her notes actually included a specification of what is considered to be the first algorithm specifically intended for implementation on a 'computer'. This algorithm was published in full in a peer-reviewed publication, thus making it 'open source'