diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 4ab01cb25050c1aacf72aa2f2eda972e4c17d918..f16599c2151da6496bd16fd960bb83e1256fa7cf 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -833,8 +833,16 @@ def remove(self, query_spec, list_name=user_speclist_name, force=False):
 
         if not matches:
             # concrete specs match against concrete specs in the env
+            # by *dag hash*, not build hash.
+            dag_hashes_in_order = [
+                self.specs_by_hash[build_hash].dag_hash()
+                for build_hash in self.concretized_order
+            ]
+
             specs_hashes = zip(
-                self.concretized_user_specs, self.concretized_order)
+                self.concretized_user_specs, dag_hashes_in_order
+            )
+
             matches = [
                 s for s, h in specs_hashes
                 if query_spec.dag_hash() == h