First order ODE - appropriate method I'm trying to solve the following ODE
$y'(x)=2y -x$
I tried to solve it with the method of variation of constants and it worked.
I considered the homogenous equation without the last term ($-x$),and I found the solution of the homogenous equation $y_h=C e^{2x}$.
Then, I considered the function $y(x)=C(x)e^{2x}$, and $y^{'}(x)=C^{'}(x)e^{2x}+2C(x)e^{2x}$.
By plugging these 2 equations in the initial ODE, I got
$C^{'}(x)=\frac{-x}{e^{2x}}$
Then, I integrated $C'(x)$, and the particular solution , using $C(x)$, is given by
$y_p=\frac{1}{4} (2x+1)$
Then, the general solution is given by
$y(x)=y_h(x)+y_p(x) =\frac{1}{4}(2x+1) +Ce^{2x}$
The question is: why am I allowed to use the method of variation of constants? I understood how to use it, but when I can use it?

You are "allowed" to use a particular method when it works! THAT is how you solve problems.  You TRY something and if it works great.  If it doesn't work, try something else.
