(geometric) intuition behind divisor class group I'm taking classes in algebraic geometry and riemann surfaces, and in both these classes the divisor class group of a (certain kind of) scheme/riemann surface $X$ is defined roughly by "divisors mod linear equivalence". I'm looking for a clear intuition/motivation for defining such a group $\text{Cl}(X)$, because I can't really seem to find it anywhere. Any help is appreciated :)
 A: (1) Here is some classical motivation. Given finitely many points $z_1, \dots, z_k \in \mathbb{C}$ and integers $n_1, \dots, n_k \in \mathbb{Z}$, one can construct a meromorphic function $f: \mathbb{C} \dashrightarrow \mathbb{C}$ whose only zeros and poles occur at the $z_i$, and such that the order of $f$ at $z_i$ is $n_i$. Of course, such a function is given by
$$
f(z) = \prod_{i=1}^{k} (z - z_i)^{n_i}.
$$
There are a few ways to make this problem more interesting. One is to allow the collection of points $\{z_1, \dots, z_k\}$ to become infinite, in which case it becomes an issue of complex analysis. However, we will consider the generalization to complex manifolds other than $\mathbb{C}$. 
So, let $X$ denote a general connected complex manifold of dimension 1. Given finitely many points $z_i \in X$ and $n_i \in \mathbb{Z}$, can we construct a meromorphic function $f$ on $X$ with $\text{ord}_{z_i}(f) = n_i$ for all $i$, and with no other zeros and poles? The answer, in general, is no. For example, it is impossible to construct a non-constant meromorphic function without poles on a compact $X$. 
To quantify this failure, one can form the free abelian group $\text{Div}(X)$ on the points of $X$. Let $\tilde{K}(X)$ denote the subfield of $K(X)$ generated by the meromorphic functions with finitely many zeros and poles (totally non-standard notation, but I don't know a good one). We can associate to each nonzero meromorphic function $f \in \tilde{K}(X)$ the element $\sum_{z \in X} \text{ord}_{z}(f) [z] \in \text{Div}(X)$. The image of this homomorphism is denoted $\text{Prin}(X)$. The quotient 
$$
\text{Cl}(X) = \text{Div}(X)/\text{Prin}(X)
$$ 
then measures the failure of this 'prescription problem' on $X$. It is an invariant of $X$ up to isomorphic of complex manifolds. 
If $\text{dim}(X) > 1$, the question ceases to be interesting as phrased. Indeed, Hartogs' theorem implies that in this case it is always possible to extend a non-vanishing holomorphic function $f$ on an open $U \setminus \{z\}$ over the point $z$ in such a way that $f(z) \neq 0$. More generally, the zeros and poles of $f$ occur along codimension 1 analytic subvarieties of $X$. Along any such subvariety, it is still possible to assign to $f$ an 'order'. For example, consider $f(z_0, z_1) = z_0/z_1$ on $\mathbb{C}^2$. It vanishes to order 1 on the plane $z_0  = 0$, and has a pole of order 1 on the plane $z_1 = 0$. Mimicking the discussion above, we associate to $X$ the free abelian group $\text{Div}(X)$ on the codimension 1 analytic subvarieties, and quotient out by those divisors defined by meromorphic functions to define the class group $\text{Cl}(X)$. 
By the way, if $X$ is compact, then the set of zeros and poles of a meromorphic function $f$ has only finitely many irreducible components (for the case of dimension 1, this is the identity theorem). So in this case there is in fact a well defined homomorphism $K(X)^* \rightarrow \text{Div}(X)$ from the meromorphic function field, and $\text{Cl}(X)$ is the cokernel. 
(2) In algebraic geometry, one tries to mimic the discussion of (1). Let $X$ be an arbitrary integral scheme. The appropriate analogue of the meromorphic function field of $X$ is its field of rational functions, $K(X)$ (when $X$ is a projective $\mathbb{C}$-variety, this agrees with the meromorphic function field of the associated complex analytic variety). Of course, the analogue of a codimension 1 analytic subvariety is a codimension 1 integral closed subscheme $Y \hookrightarrow X$. One then defines $\text{Div}(X)$ to be the free abelian group on such subschemes, which are called prime divisors.
The basic headache that arises is that there is no meaningful way in general to assign to $f \in K(X)$ an order $\text{ord}_{Y}(f)$ along each prime divisor $Y$. In complex geometry, the definition of $\text{ord}_Y(f)$ goes like this. Given any open set $U \subset X$ which meets $Y$, it is possible to shrink $U$ to an open $U'$ (which still meets $Y$), such that $Y \cap U'$ is defined by the vanishing of a single holomorphic function $\pi$ on $U$. The one shows that, shrinking $U'$ if necessary, $f \vert_{U'}$ can be written as $h \pi^n$, for $h$ and non-vanishing holomorphic function and $n \in \mathbb{Z}$ an integer. One sets $\text{ord}_{Y}(f) = n$, which one then proves is well-defined. 
In the algebraic setting, we are then looking for an element $\pi \in K(X)$ such that any $f \in K(X)^*$ can be uniquely expressed as $f = h\pi^n$, for $h \in K(X)$ a unit on an open neighborhood meeting $Y$. In other words, $h$ should be a unit of the ring of germs $\mathscr{O}_{X, \eta} \subset K(X)$. This property of an element $\pi$ is equivalent to asking for $\pi$ to generate the maximal ideal of $\mathscr{O}_{X,\eta}$ (since $\text{Frac}(\mathscr{O}_{X,\eta}) = K(X)$, by integrality). Therefore, the relevant condition is that each local ring $\mathscr{O}_{X,\eta}$, for $\eta$ the generic point of a codimension 1 irreducible closed subset, should have a principal maximal ideal. That is, this ring should be a 'discrete valuation ring.' 
The basic way to guarantee that this hypothesis is satisfied is to ask for $X$ to be integral, noetherian, and regular in codimension 1. Hopefully this discussion elucidates that strange hypothesis, which you'll find in Hartshorne. 
(3) Suppose that $X$ is a nonsingular projective $k$-variety. Then there is a closed immersion $X \hookrightarrow \mathbb{P}^n_k$. It is possible to intersect a prime divisor $H$ on $\mathbb{P}^n_k$ which does not contain $X$ with $X$ to yield an effective divisor $H \cap X \in \text{Div}(X)$ (Hartshorne, Exercise II.6.2 has the details). In particular, if $H$ runs over the hyperplanes in $\mathbb{P}^n_k$ not containing $X$, a family of effective divisors on $X$ is swept out. Any two divisors in this family are linearly equivalent, and if $D = H_0 \cap X$ for some hyperplane $H_0$, then any effective divisor $D'$ linearly equivalent to $D$ is $H_1 \cap X$ for some other hyperplane $H_1$. 
We completely recover the projective embedding $X \hookrightarrow \mathbb{P}^n_k$ by studying this family of divisors. The converse question, of when a class of $\text{Cl}(X)$ arises from a projective embedding in this way, is extremely rich. Such classes are called very ample, and as you would expect, not every divisor class is very ample. They can be characterized cohomologically (Hartshorne, section II.7 is an introduction to these questions).
(4) There is a lot of geometry focused on studying the vector bundles on a space, manifold, or scheme $X$. The base case of this study is that of line bundles. The special fact about line bundles on a scheme $X$ is that the set of isomorphism classes of line bundles, $\text{Pic}(X)$, is naturally an abelian group under the tensor product. The remarkable fact is that when Weil divisors are defined on $X$, there is an injection $\text{Pic}(X) \hookrightarrow \text{Cl}(X)$, which is an isomorphism when $X$ is nonsingular (more generally, when it is locally factorial). So, divisors provide a tool for studying line bundles.
(5) You asked for geometric motivation, but here is some number theory. Let $K/\mathbb{Q}$ denote a number field, i.e. a finite extension of $\mathbb{Q}$. The integral closure of $\mathbb{Z}$ in $K$ is the ring of integers $\mathcal{O}_K$. It is a fundamental fact that $\mathcal{O}_K$ is not a UFD (for example, when $K = \mathbb{Z}[\sqrt{-5}]$). It is always, however, a Dedekind domain (all of its localizations at nonzero primes are DVRs). It is a fact that a noetherian domain $R$ is a UFD if and only if $X = \text{Spec} \, R$ is normal, and $\text{Cl}(X) = 0$. Therefore, $\text{Cl}(\text{Spec} \,\mathcal{O}_K)$ measures the extent to which $\mathcal{O}_K$ fails to be a UFD. It is a fundamental theorem of algebraic number theory (the class number theorem) that this group is a finite group.
