$\begingroup$

See the Wikipedia page on Eilenberg-Mac Lane spaces for an even better statement: For every group $G$ there is a $CW$-complex $K(G,1)$ (unique up to homotopy equivalence) such that $\pi_1(K(G,1)) \cong G$ and $\pi_{n}(K(G,1)) = 0$ for all $n

eq 1$. This is also true for every other value of $1$ (to quote Mariano Suárez-Alvarez) and abelian $G$ and proofs of these statements can be found in almost all books on algebraic topology.

A nice and and rather explicit example for a space with fundamental group $\mathbb{Q}$ can be constructed using the theory of graphs of groups, see exercise 6 on page 96 of Hatcher's book.

In 1988, Shelah proved that there is no "nice" compact space with fundamental group $\mathbb{Q}$, where nice means metric, compact (hence separable) path connected and locally path connected. Indeed, Shelah has shown the fundamental group of a nice compact space is either finitely generated or has the cardinality of the continuum.