A doubt in a Wikipedia article discussing Bertrand's theorem Wikipedia while deriving Bertrands theorem writes after some steps:

...For the orbits to be closed, $β$ must be a rational number. What's more, it must be the same rational number for all radii, since $β$ cannot change continuously.
Using the definition of $J$ along with equation (1) we get


$J^{\prime}\left(u_{0}\right)=\frac{2}{u_{0}}\left[\frac{m}{L^{2} u_{0}^{2}} f\left(\frac{1}{u_{0}}\right)\right]-\left[\frac{m}{L^{2} u_{0}^{2}} f\left(\frac{1}{u_{0}}\right)\right] \frac{1}{f\left(\frac{1}{u_{0}}\right)} \frac{d}{d u_{0}} f\left(\frac{1}{u_{0}}\right)=-2+\frac{u_{0}}{f\left(\frac{1}{v_{0}}\right)} \frac{d}{d u_{0}} f\left(\frac{1}{u_{0}}\right)=1-\beta^{2}$

where $J^{\prime}\left(u_{0}\right)=\left.\frac{d J}{d u}\right|_{u_{0}}$

Since this must hold for any value of $u_0$ then
${\displaystyle {\frac {df}{dr}}=(\beta ^{2}-3){\frac {f}{r}}}$ and hence
${\displaystyle f(r)=-{\frac {k}{r^{3-\beta ^{2}}}}.}$

and then we find that
${\displaystyle J(u)={\frac {mk}{L^{2}}}u^{1-\beta ^{2}}.}$
However by a similar argument we can say that since $β$ is a constant then we can directly solve
$J^{\prime}(u)=1-\beta^{2}$ and find that $J=\left(1-β^{2}\right) u$ which is wrong.
Were did I go wrong.
Link:https://en.wikipedia.org/wiki/Bertrand%27s_theorem#math_2
 A: You're forgetting that for fixed $m$, $u_0$ is a function of $L$. $J(u,L)$ is function of two variables, not one, so your differential equation for "$J'(u)$" isn't so simple.
If we take $m$ to be constant, then in principle $u$ and $L$ are independent parameters. The function $J(u,L)$ is defined via
$$J(u,L)=-\frac{m}{L^2u^2}f\left(\frac{1}{u}\right) \tag{1}$$
where $f(r)$ is some random force function. In the discussion you quoted, we are expanding about an arbitrary point $u_0$ defined by the following constraint equation:
$$u_0=J(u_0,L) \tag{2}$$
Here we can solve for $u_0$ in terms of $L$, to get $u_0(L)$, which we will assume to be single-valued for simplicity. This is intuitive: for a specified value of angular momentum $L$, the value $u_0(L)$ gives a circular orbit. Likewise, we can flip this around write:
$$u=J(u,L_0)\longrightarrow L_0(u)\tag{3}$$
For a specified radius $u$, the angular momentum $L_0(u)$ gives a circular orbit.
In that wikipedia article, they found that $\beta$ is independent of $L$ (or equivalently $u_0$, if $u_0(L)$ is a one-to-one function):
$$\frac{\partial J(u_0(L),L)}{\partial u}=1-\beta^2 \tag{4}$$
You cannot integrate this equation with respect to $u$ because there is no $u$ involved actually - we are evaluating at $u=u_0(L)$. It's a function of $L$. Likewise we can rewrite (4) as
$$\frac{\partial J(u,L_0(u))}{\partial u}=1-\beta^2 \tag{5}$$
Still, you cannot simply integrate and obtain $J(u,L_0(u))$ because that's not how the chain rule works:
$$\frac{d}{du}J(u,L_0(u))=\frac{\partial}{\partial u}J(u,L_0(u))+\frac{\partial J(u,L_0(u))}{\partial L} \frac{dL_0}{du} \tag{6}$$
So you still need to calculate $\frac{dL_0}{du}$ in order to integrate and obtain $J(u,L_0(u))$.
What the article does is use a clever manipulation to derive an equation that does away with explicit $L$ dependence, leaving a single-variable differential equation in $u$ to be solved.
$$\frac{\partial J (u_0(L),L)}{\partial u}=1-\beta^2=-2+\frac{u_0(L)}{f\left(\frac{1}{u_0(L)}\right)}\left[\frac{d}{du}f\left(\frac{1}{u}\right)\right]_{u=u_0(L)} \tag{7}$$
In (7), we find that all the dependence on $L$ is through the function $u_0(L)$. Since $u_0(L)$ is assumed to be a smooth function of $L$, we can really just drop the $L$ and solve for $u_0$. This is equivalent to having derived
$$\frac{\partial J (u,L_0(u))}{\partial u}=1-\beta^2=-2+\frac{u}{f\left(\frac{1}{u}\right)}\frac{d}{du}f\left(\frac{1}{u}\right)\tag{8}$$
This gives a differential equation for $f(r)$ which we can solve, and work back to get $J(u,L)$.
A: $J'(u_{0}) = 1-\beta^2$ is different from $J'(u) = 1-\beta^2$.
After you evaluate at a point ($J'(u_{0})$) you cannot use it as a differential equation.
Example: let
$J = 1 + u + u^{2}$
so that
$J' = 1 + 2 u$.
Evaluate at $u=u_{0}$ so that
$J'(u_{0}) = 1+2u_{0}$.
From here, you would be wrong to integrate, finding that
$J = (1 + 2 u_{0}) u$.
