Start with
[tex]\dfrac{dy}{dx}=\dfrac{y}{x}[/tex]
Separate the variables:
[tex]\dfrac{dy}{y} = \dfrac{dx}{x}[/tex]
Integrate both parts:
[tex]\displaystyle \int \dfrac{dy}{y} = \int\dfrac{dx}{x}[/tex]
Which implies
[tex]\log(y) = \log(x)+c[/tex]
Solving for y:
[tex]y = e^{\log(x)+c} = e^{\log(x)}e^c=xe^c[/tex]
Since [tex]e^c[/tex] is itself a constant, let's rename it [tex]c_1[/tex].
Fix the additive constant imposing the condition:
[tex]y(1) = c_1\cdot 1 = -2\iff c_1=-2[/tex]
So, the solution is
[tex]y(x) = -2x[/tex]