Free modules are another instance of free objects. (see this post for a discussion on free objects and the construction of the free group.) They are the modules satisfying a universal property analogue to that of free groups. Here is a more constructive definition:

Definition: Let $S$ be a set and $R$ be a ring. An $R$-module $F$ is free on $S$ if for all $0 \neq x \in F,$ there exist unique non-zero $r_1, \ldots r_n \in R$ and unique non-zero $s_1, \ldots, s_n \in S$ such that $x = \sum_{i=1}^nr_is_i$ for some $n \in \textbf{N}.$ The set $S$ is said to be a basis or a set of free generators for $F.$ If $R$ is commutative, we call $|S|$ the rank of $F.$

Note that there is a natural injection $\iota : S \to F$ identifying $s \in S$ with $1_Rs \in F.$

This definition coincides with our intuition that the only relations among elements of $F$ should be the minimal relations required for $F$ to be a module. For example, the integers modulo $n$, $\mathbf{Z}_n$ is not a free $\mathbf{Z}$-module on any set. Indeed, although any element $x\in \mathbf{Z}_n$ can be uniquely written as an element of the underlying set, we have $x = (n+1)x = (2n+1)x = \cdots$ so we don’t have unicity in the ring elements, as the definition requires.

To construct a free $R$-module on a set $S,$ consider the free abelian group on $S,$ which you can obtain by quotienting the free group on $S$, $FG(S)$ by the normal subgroup generated by the set of all elements of the form $ab - ba$ in $FG(S).$ (This will satisfy the analog universal property for abelian groups.) This group can be identified with

$\textbf{Ab}(S) := \{ \displaystyle\sum_{finite} \epsilon_is_i \mid s_i \in S; \epsilon_i \in \{ -1_R, 1_R \} \}$

where the operation is still concatenation of words but written additively. We now naturally define the free $R$-module over $A$ by

$F(S) = \{ \displaystyle\sum_{finite}r_is_i \mid r_i \in R; s_i \in S \}$

with the $R$-action defined as $r(\sum r_is_i) = \sum (rr_i)s_i.$ This is easily seen to satisfy the defining properties of a module and the universal property of free modules:

Theorem: (Universal property) For $S$ a set and $R$ a unitary ring, the $R$-module $F(S)$ constructed above satisfy the universal property of free modules. In other words, for every $R$-module $M$ and every map $\varphi : S \to M,$ there exists a unique $R$-module homomorphism $\phi : F(S) \to M$ such that the following diagram commutes:

Proof: Let $\iota : S \hookrightarrow F(S)$ be the natural inclusion $\iota(s) = 1s.$ Define $\phi : F(S) \to M$ on $\iota(S) \subset F(S)$ as $\phi(1s) = \varphi(s).$ Then, since $\iota(S)$ generates $F(S),$ $\phi$ extends uniquely by linearity to an $R$-module homomorphism on $F(S)$ and we have $\varphi = \phi \circ \iota$ as wanted.

QED

Note that as in the case of the free groups, this property uniquely characterizes free modules up to isomorphism.

Reference: D. S. Dummit, R. M. Foote, Abstract Algebra, 3rd ed.