A modular device for compressing gaseous fluid includes a first stage with a first hot chamber, a second cold chamber, a piston assembly separating the first and second chambers inside a main enclosure, a regenerative heat exchanger establishing a fluid communication between the first and second chambers by at least a first communication line, and optionally third and fourth chambers separated by a fixed divider separating the third and fourth chambers placed in communication by a second communication line. It thus includes a compressor with one, two, or four stages based on a modular architecture with common components.