They did it mainly under the cover of night. Parties were sent out during the cover of darkness to set up wire and install improvised explosive charges that were like home made mines. These parties were called Wiring Parties and it was a very dangerous and physical job to do. Not only did they have to be quiet not to be heard by the enemy, they also had to crawl over bodies etc. with heavy and sharp wire with them. This lead to a lot of innovations mainly done by the men themselves. Much of the metal traditionally used to hold the wire elevated was changed to wood etc. all to keep the level of sound to a minimum.
These same Wiring Parties also sabotaged the defences of the enemy, cutting open gaps in the enemy wiring to allow their own troops to get through easier.
I'm myself a combat engineer and a part of the pride of the unit is to learn about the history of combat engineering from around the world. It is very interesting indeed. Makes me feel spoiled when we got to use hydraulics, night vision and plastic explosive, when these guys had to improvise wooden sticks and you name it.
For more on the subject I'd suggest the book: World War I by Jennifer D. Keene, Greenwood Publishing Group 2006
Edit: A typo.
I answered in the cross-post to /r/WWI, but maybe someone around here is also interested in this booklet available on archive.org that describes the process of building barbed wire in more detail than you need: Wire entanglements : addenda no. 1 to Engineer Field Manual (1918)
For staying alive in No Man's Land while working I would add to /u/RamblinRambo's response that there were also usually patrols out to cover your own working parties, and/or attempting to attack the enemy working parties during the night. Source: that booklet linked to above (although there are other books describing it in more detail, just can't think right now)
In addition to the risk of enemy patrols, there were random shelling of no man's land using mortars and artillery, sweeps by machine-guns, and sniper-rifles set up during the day to fire randomly at night at some location the enemy might show up. That latter practics is described in Notes for Infantry Officers on Trench Warfare from 1916 (there is a reprint from a few years ago) as "Fixed rifle batteries for keeping certain points or localities under fire by night are often extremely useful as a means of hampering the enemy's work and causing loss." (I know this was described in more detail including sketches of how to mount the rifles in some other book, but can't remember which one.)