Why did God command killing in the Old Testament?

While spending time with friends, a question was asked regarding violence in the Old Testament. The issue with which they were struggling was a question about the command not to “commit murder”, yet God commands Isreal to “destroy” the Canaanites and, later on, the Amalekites (Deuteronomy 20:16-18; 1 Samuel 15:2-3, etc.) Does this mean God [ ]