The best way to keep glasses clean in a cupboard is to clean and dry them thoroughly before you put them in there. Any dirt or moisture will just get worse if it’s sitting in a cupboard. However, there are other ways to keep them clean in a cupboard.
No matter whether you store them rim side up or rim side down, investing in a kitchen cabinet liner is a great way to keep your glasses clean. This will create a barrier between the potentially dirty cabinets and give you a clean surface to place them on.
Alternatively, you could hang your glasses from the cabinet instead. By doing this, you can keep the glasses away from the cabinet completely. This will only work when you have glasses with stems, though.