Given the limitations of the social sciences, it is impossible to know for sure if the death penalty deters people from committing murder. There is simply no good and feasible way to test the impact of the death penalty on the murder rate. Let us examine two of the factors that make this so.
First, the death penalty in the United States, at least, is not something that is certain or swift. In order for a punishment to deter us from committing a given act, we must be sure that we will be punished in that way. In the United States, not even the states that execute the most people impose the death penalty on everyone who commits a murder. Therefore, it will be hard for the death penalty to deter murder because people who think of killing (even if they weigh the potential consequences) will be able to think that they will not be given the death penalty. Thus, it is hard to tell if capital punishment does deter murder because of the way it is carried out in the US.
Second, we cannot run experiments to determine if the death penalty does deter people from killing. We might think, for example, that we could simply compare the murder rates in states with and without the death penalty. However, that does not necessarily tell us anything because those states could be very different in other ways (income and culture, for example) that have nothing to do with capital punishment but which affect their murder rates.
For these two reasons, and others, there is simply no way to know for sure if the death penalty acts as a deterrent.