Suppose $(\Omega, \mathcal F, P)$ is our probability space. $X, Y$ are two real-valued random variables (Borel measurable) defined on this space. In the book "Probability: Theory and Examples", (1) $X$ and $Y$ have the same distribution if they induce the same measure on $\mathbb R$, that is $P(X \le x) = P(Y \le x)$ for all $x \in \mathbb R$. (2)In another source, two random variables have the same distribution if for all $B \in \mathcal B(\mathbb R)$, $P(X \in B) = P(Y \in B)$.
The two definition should be the same. (2) implies (1) trivially. I am having trouble to see why (1) implies (2). I know set with the form $(-\infty, x]$ generates the Borel $\sigma$-algebra on $\mathbb R$. But in my mind, for any Borel set, in general we can only approximate it by closed (open) sets. How could we conclude the general case just by the equality on the closed sets?