Edit: dug up some Polybios and added some ancillāria to make things more round.
If convenient, ancient armies used boats or rough rafts to ferry men and equipment across, or else created a floating bridge (with planks) out of boats (with prows turned up-river). Hannibal, when he was crossing the Rhone river in Gaul upon his invasion of Italy, had such a strategy:
(Polybios 3.42) Hannibal, on reaching the neighbourhood of the river, at once set about attempting to cross it where the stream is single at a distance of about four days' march from the sea. 2 Doing his best to make friends with the inhabitants of the bank, he bought up all their canoes and boats, amounting to a considerable number, since many of the people on the banks of the Rhone engage in maritime traffic. 3 He also got from them the logs suitable for making the canoes, so that in two days he had an innumerable quantity of ferry-boats, every one doing his best to dispense with any assistance and relying on himself for his chance of getting across. 4 In the meantime a large force of barbarians had gathered on the opposite bank to prevent the Carthaginians from crossing. 5 Hannibal observing this and concluding that as things stood it was neither possible to force a crossing in face of such a strong hostile force nor to put it off, lest he should find himself attacked on all sides, 6 sent off on the third night after his arrival a portion of his army, giving them native guides and placing them under the command of Hanno, the son of Bomilcar the Suffete. Advancing up the bank of the river for two hundred stades they reached a place at which the stream divides, forming an island, and here they stopped. 8 Using the timber they found ready to hand and either nailing or lashing logs together they soon constructed a number of rafts sufficient for their present need, and on these they crossed in safety, meeting with no opposition...
As a side note, Goldsworthy (Fall of Carthage p. 160) mentions some of Hannibal's men swimming across with the aid of inflated animal skins. In America we call these "swimmies." This detail is not in Polybios, though, so I'm not sure where he got that information.
If boats were not available, or there was no timber to build rafts, or it was not deemed appropriate, the Romans had the option to bridge the river, like Caesar's legions did at the Rhine in 55 BCE (not all ancient armies were capable of this engineering feat). You can read Caesar's detailed (and long) description below, and I see no need to paraphrase the man when he is so obviously excited to describe this event in his own words. (see below). He tells us that this bridge was especially elaborate, in order to impress his foes. If there was to be a more permanent crossing, the bridge was usually made of stone instead of timber and used a simple but powerful engineering technique of arches with keystones to span the space. Many roman bridges still survive in Europe today, like the one at Alcantara in Spain, the one at Aleppo in Syria(sadly now damaged), or the one at Montignies-Saint-Christophe in France. These all show slightly different construction techniques and varying span size. As a side note, there are dozens of Roman bridges in Europe that survived 2,000 years only to be destroyed during World War II (by both the Germans and the Allies). WW2 was not kind to bridges regardless of their age. The Roman bridge at Arles was one such casualty of that great conflict.
Rivers were a major obstacle to large armies and without a functioning bridge, enough boats to ferry (and the right conditions as far as weather and enemies), or the know-how and opportunity to build a new bridge, the larger rivers were impassable barriers.
(BG 4.17) Caesar, for those reasons which I have mentioned, had resolved to cross the Rhine; but to cross by ships he neither deemed to be sufficiently safe, nor considered consistent with his own dignity or that of the Roman people. Therefore, although the greatest difficulty in forming a bridge was presented to him, on account of the breadth, rapidity, and depth of the river, he nevertheless considered that it ought to be attempted by him, or that his army ought not otherwise to be led over. He devised this plan of a bridge. He joined together at the distance of two feet, two piles, each a foot and a half thick, sharpened a little at the lower end, and proportioned in length, to the depth of the river. After he had, by means of engines, sunk these into the river, and fixed them at the bottom, and then driven them in with rammers, not quite perpendicularly, dike a stake, but bending forward and sloping, so as to incline in the direction of the current of the river; he also placed two [other piles] opposite to these, at the distance of forty feet lower down, fastened together in the same manner, but directed against the force and current of the river. Both these, moreover, were kept firmly apart by beams two feet thick (the space which the binding of the piles occupied), laid in at their extremities between two braces on each side, and in consequence of these being in different directions and fastened on sides the one opposite to the other, so great was the strength of the work, and such the arrangement of the materials, that in proportion as the greater body of water dashed against the bridge, so much the closer were its parts held fastened together. These beams were bound together by timber laid over them, in the direction of the length of the bridge, and were [then] covered over with laths and hurdles; and in addition to this, piles were driven into the water obliquely, at the lower side of the bridge, and these, serving as buttresses, and being connected with every portion of the work, sustained the force of the stream: and there were others also above the bridge, at a moderate distance; that if trunks of trees or vessels were floated down the river by the barbarians for the purpose of destroying the work, the violence of such things might be diminished by these defenses, and might not injure the bridge. (4.18) Within ten days after the timber began to be collected, the whole work was completed, and the whole army led over. Caesar, leaving a strong guard at each end of the bridge, hastens into the territories of the Sigambri. In the mean time, embassadors from several nations come to him, whom, on their suing for peace and alliance, he answers in a courteous manner, and orders hostages to be brought to him. But the Sigambri, at the very time the bridge was begun to be built, made preparations for a flight (by the advice of such of the Tenchtheri and Usipetes as they had among them), and quitted their territories, and conveyed away all their possessions, and concealed themselves in deserts and woods. (4.19) Caesar, having remained in their territories a few days, and burned all their villages and houses, and cut down their corn, proceeded into the territories of the Ubii; and having promised them his assistance, if they were ever harassed by the Suevi, he learned from them these particulars: that the Suevi, after they had by means of their scouts found that the bridge was being built, had called a council, according to their custom, and sent orders to all parts of their state to remove from the towns and convey their children, wives, and all their possessions into the woods, and that all who could bear arms should assemble in one place; that the place thus chosen was nearly the centre of those regions which the Suevi possessed; that in this spot they had resolved to await the arrival of the Romans, and give them battle there. When Caesar discovered this, having already accomplished all these things on account of which he had resolved to lead his army over, namely, to strike fear into the Germans, take vengeance on the Sigambri, and free the Ubii from the invasion of the Suevi, having spent altogether eighteen days beyond the Rhine, and thinking he had advanced far enough to serve both honor and interest, he returned into Gaul, and cut down the bridge. (translation by Bohn).