Morphism epimorphism if and only if surjective In the category of sets, I want to prove that a morphism is an epimorphism if and only if it is surjective.
In both directions, I'm having a hard time approaching this problem.
This is how far I got.
$$\text{Morphism is epimorphism} \implies \text{Morphism is surjective}:$$
Let $\phi: A \to B$ be an epimorphism. 
For any morphisms $\beta,\beta': B \to Y$, we have 
$$ \beta \ \circ \ \phi = \beta' \ \circ \phi \implies \beta = \beta'.
$$
$$\vdots$$
$$\text{Morphism is surjective}\implies \text{Morphism is epimorphism} :$$
Pick an arbitrary $b \in B$.
Since $\phi$ is surjective there exists an $a\in A$ such that $b = \phi(a)$.
Set $y = \beta(\phi(a)) = \beta'(\phi(a))$.
$$\vdots$$ 

If $f:X\to Y$ is an epimorphism, define $g_1:Y\to\{0,1\}$ with $g_1(y)=0$ for all $y\in Y$, and $$g_2(y)=\begin{cases}0&y\in\mathrm{im}(f)\\1&\text{otherwise}\end{cases}$$
Then for $x\in X$ we see that $g_1\circ f (x)=0= g_2\circ f(x)$. From the property of epimorphism, this means that $g_1=g_2$, which is only possible if $\mathrm{im}(f)$ is all of $Y$.
Now, if $f$ is surjective, then take $g_1,g_2:Y\to Z$ with $g_1\circ f = g_2\circ f$. Then for any $y\in Y$, we can find $x\in X$ such that $f(x)=y$. Then $$g_1(y)=g_1\circ f (x)=g_2\circ f(x)=g_2(y)$$
So $g_1=g_2$.
