Well, before there were tunnels, people used channels (artificial water passages) to navigate. These channels passed above the ground, just like our current roads and/or railways. However, some obstacles emerged along the path, like mountains, for example. In order to pass these great obstacles, the first tunnels were developed.
How you built a tunnel depends on what material it has to go through: hard soil, soft soil, water (the most difficult environment to built tunnels in), hard rock, soft rock. Because of that, planning is a very important part of fabricating a tunnel successfully. The engineers make a complete geological analysis of the place to determine which kind of material will be found and to evaluate the risks of different possible places of construction. Many factors are considered, but the most important ones are: the types of soil and rock; the weak areas, including faults and shear zones; underground waters, including flow pattern and pressure; especial risks such as heat, gases and fault lines. Usually, a tunnel goes through more than one type of material, therefore facing different risks.
The process of building a tunnel and advancing the excavation can be long and boring, requiring explosions, manual excavation and perfuration. The engineers often use two basic techniques to dig a tunnel: the full excavation method and the "top-heading-and-bench" method. In the first one, they dig the whole tunnel diameter at the same time. This is the most appropriate technique for tunnels that pass under strong soil or the ones that are smaller. In the second method, the workers dig a smaller tunnel to begin with, the driver tunnel. Once the driver enters a certain distance within the rock, the workers start to dig right under these upper driver's layer. This second tunnel is called berm. One advantage of this method is that the engineers can use the driver tunnel to measure the rock's stability before continuing the project.
Finally, unless the tunnel is small, it is essential to provide safe work conditions and to guarantee the safety of travelers after the tunnel is put in operation. One of the most valuable concerns is ventilation, a problem which is almost always magnified by the gases released by trains and automobiles, but ventilators usually do the trick.