To fit the zero-intercept linear regression model $y=\alpha x + \epsilon$ to your data $(x_1,y_1),\ldots,(x_n,y_n)$, the least squares estimator of $\alpha$ minimizes the error function
$$
L(\alpha):=\sum_{i=1}^n(y_i-\alpha x_i)^2.\tag1
$$
Use calculus to minimize $L$, treating everything except $\alpha$ as constant. Differentiating (1) wrt $\alpha$ gives
$$
L'(\alpha) = \sum2(y_i-\alpha x_i)(-x_i)=-2\left(\sum x_iy_i - \alpha\sum x_i^2\right).\tag2
$$
Setting (2) to zero yields the equation
$$
\sum x_iy_i=\alpha\sum x_i^2\tag3
$$
which you can solve for $\alpha$ to obtain the estimator for the slope:
$$\hat\alpha = \frac{\sum x_iy_i}{\sum x_i^2}.
$$
Remember to check that the second derivative of $L$ is positive, to confirm that $L$ is minimized for this $\hat\alpha$. Indeed, $L''(\alpha)=2\sum x_i^2$, which doesn't depend on $\alpha$, and is positive except in the degenerate case where all the $x$'s are exactly zero. In that case you will agree that there's no unique line passing through the origin that best fits the data.