Let $R$ be integral domain. Show that if $2$ principal ideals $(a)$ and $(a')$ are equal (where $a,a'\in R$) then there exists $u\in R^{\times}$ such that, $a'=ua$
Now if $(a)=(a')$ then $a\in(a')$ and $a'\in(a)$ therefore there exists some elements $u,v$ in $R$, such that $a=ua'$ and $a'=va$, which implies that $a=uva$.
Hence $uv=1$ and $u$ is a unit, $u\in R^{\times}(=R\setminus\{0\})$
but I didn't make use of the property that, $R$ is an integral domain, so $R$ can be any ring or not ?
You stated that $a=uva$ implies $uv = 1$. This is the cancellation law which holds in integral domains (but not for any ring).
To prove this for integral domains, note that if $ca=cb$ for $c \neq 0$, then $c(a-b)=0$ so $a=b$.
A counter-example for a ring which is not an integral domain is $\mathbb{Z}/4\mathbb{Z}$, where $2 \cdot 1 = 2 \cdot 3$.