First, note that we can only measure in the computational basis in quantum computing (at least at the moment). But this is not a problem since
\begin{align}
\langle \psi | H | \psi \rangle = \langle \psi | 2X + 0.5 Z | \psi \rangle &= 2\langle \psi | X |\psi \rangle + 0.5\langle \psi|Z|\psi\rangle \\
&= 2\langle \psi|HZH|\psi\rangle + 0.5\langle\psi|Z|\psi\rangle \\
&= 2\langle\psi H|Z|H\psi\rangle + 0.5\langle\psi|Z|\psi\rangle
\end{align}
This means we need to create to different quantum circuits to the problem. One for each term below. Now $|\psi \rangle = U |\psi\rangle_{ref} $ where $|\psi\rangle_{ref}$ can be taken as $|0\rangle$ if you wish. The unitary matrix $U$ can be taken as what you see fit. For instance, if you believe that the eigenstate will have only real coefficients then you can use take $U = RY(\theta)$. If taken $U$ to be $RY$ then we would have the following two circuits:
To compute the expectation, you would need to do sufficient enough shots to build a statistical distribution. Since we measure in the computational (Z) basis, $|0\rangle$ corresponds to the $+1$ eigenspace, and $|1\rangle$ corresponds to the $-1$ eigenspace.
To see this more clearly, let's suppose you run 1000 shots experiment on circuit 1, to calculate $\langle \psi | X | \psi \rangle$, and you recorded/measured 700 times the state $|0\rangle$ and 300 times the state $|1\rangle$ from your 1000 shots. This implies, that $$\langle \psi | X | \psi \rangle \approx \dfrac{700 - 300}{1000} = 0.4$$
Then similarly, you do 1000 shots experiment on your second circuit to calculate $\langle \psi |Z| \psi \rangle$ and you measured 900 times the state $|0\rangle$ and 100 times the state $|1\rangle$ then this implies $$ \langle \psi | Z | \psi \rangle \approx \dfrac{900 - 100}{1000} = 0.8$$
Putting it altogether, we have that $$\langle \psi | H | \psi \rangle \approx 2\cdot 0.4 + 0.5\cdot0.8 = 1.2$$
Note that I used the approximation symbol, $\approx$ because to get the exact value, you must do $\infty$ number of shots.
Now that you have found what $\langle \psi | H \psi \rangle$ is for that specific $\theta$ value, you can change it in such a way that it will minimize $\langle \psi | H \psi \rangle$. So that at the next iteration, you expect something smaller, in our case, smaller than 1.2. There are many ways you can change $\theta$, depending on what optimizer you want to use. Gradient based or Gradient free. There are many classical optimizers and each has its pro and con. Here, take a look at some of the optimizer that you can use directly from Scipy. There are more sophisticated optimizer that aim specifically at Variational Quantum algorithms like VQE but those are not always available publicly so you have to write the code yourself. And you can invent your own optimizer that you think work best as well.
An important thing to note here is that our cost function, $C(\theta) = \langle \psi | H | \psi \rangle$ is bounded by the variational principle. that is, we know that $\langle \psi | H | \psi \rangle \geq E_0$ where $E_0$ is the minimum eigenvalue of $H$ and $|\psi \rangle = U(\theta) |\psi \rangle_{ref}$. Thus, by keep minimizing the expectation we found during our experiment by changing $\theta$ in the right direction, we will indeed approach this minimum value $E_0$.
If your Hamiltonian has a Pauli $Y$ in it, then you need to calculate $$\langle \psi | Y | \psi \rangle = \langle \psi | HSZHS^\dagger |\psi \rangle = \langle \psi HS | Z | HS^\dagger \psi \rangle $$
This means you need to first apply $S^\dagger$ follow by the Hadamard gate $H$ to your circuit before measuring in the computational (Z) basis. This can be visualized by the following circuit: