Catalytic hydrogenation of CO2 or CO to chemicals/fuels is of great significance in chemical engineering and the energy industry. In this work, density functional theory (DFT) calculations were carried out to investigate the hydrogenation of CO2 and CO on Ru(0001) surface to shed light on the understanding of the reaction mechanism, searching new catalysts and improving reaction efficiency. The adsorption of intermediate species (e.g., COOH, CHO and CH), reaction mechanisms, reaction selectivity and kinetics were systematically investigated. The results showed that on Ru(0001) surface, CO2 hydrogenation starts with the formation of an HCOO intermediate and produces adsorbed CHO and O species, followed by CHO dissociation to CH and O; while CO hydrogenation occurs via either a COH or CHO intermediate. Both the hydrogenation processes produce active C and CH species, which subsequently undergoes hydrogenation to CH4 or a carbon chain growth reaction. The kinetics study indicates that product selectivity (methane or liquid hydrocarbons) is determined by the competition between the two most favorable reactions: CH + H and CH + CH. Methane is the predominant product with a high H-2 fraction at normal reaction pressure; while liquid hydrocarbons are mainly produced with a large CO2/CO fraction at a relatively high pressure.