We establish well-posedness of a class of first order Hamilton-Jacobi equation in geodesic metric spaces. The result is then applied to solve a Hamilton-Jacobi equation in the Wasserstein space of probability measures, which arises from the variational formulation of a compressible Euler equation.Â