We have studied the adsorption of gas molecules (CO, NO, NO2, O2, N2, CO2, and NH3) on graphene nanoribbons (GNRs) using first principles methods. The adsorption geometries, adsorption energies, charge transfer, and electronic band structures are obtained. We find that the electronic and transport properties of the GNR with armchair-shaped edges are sensitive to the adsorption of NH3 and the system exhibits n type semiconducting behavior after NH3 adsorption. Other gas molecules have little effect on modifying the conductance of GNRs. Quantum transport calculations further indicate that NH3 molecules can be detected out of these gas molecules by GNR based sensor.