Public goods have a free rider problem. One way to solve this is to turn a public good into a private good through a legal fiction called "intellectual property". While this is one way to solve this, it does so with tremendous societal cost - effectively denying a useful tool to the vast majority so that a small number have an incentive to pay for it.
So yes you can charge for software and people do but it's probably not the optimal way to organize a society.