Locally given complex structure on a 2-plane bundle over a compact manifold can be extended globally Not any even rank real vector bundle over a smooth manifold has a complex structure, because there are even dimensional manifolds that have no almost complex structures. I am curious about the following special case: Suppose $M$ is a real compact, connected smooth manifold and $E\to M$ is an orientable real $2$-plane bundle. Also suppose, for some connected open subset $U$, $E|_U$ has a complex structure (so that it can be seen as a complex line bundle). In this case can we extend the complex structure on $E|_U$ to $E$?
 A: There are two obstructions, one of which is topological and second is geometric.

*

*The topological obstruction is that every complex vector bundle comes with a canonical orientation. Hence, you have to assume that your vector bundle $E\to M$ is orientable and its orientation extends the one coming from the complex structure on the bundle $E|_U\to U$. If $M$ is connected and $U$ is nonempty, then this extension of an orientation is unique.

In particular, if $U$ is connected (as in the edit to your question) and $E\to M$ is orientable then, after possibly replacing this orientation with the opposite one, we can assume that the orientation on $E\to M$ agrees with that of $E|_U$.
Thus, from now on, I will assume that $E\to M$ is oriented as above.


*To understand the second obstruction, note that a complex structure on a real vector bundle is a smooth family $J$ of automorphisms of the fibers $J_x: E_x\to E_x$ such that $J_x^2=-I$ for every $x\in M$. Since $E$ has rank 2 and is oriented, prescribing such $J$ is equivalent to prescribing a metric tensor $h_x$ on the fibers $E_x$ of $E$ (of course, depending smoothly on $x\in M$). Once such $h_x$   is given, then $J_x$ is the rotation by $\pi/2$ in the positive direction. Conversely, once $J_x$ is given, the metric $h_x$ (Hermitian with respect to $J_x$) is canonically defined up to scaling.

Here is an example of a non-extendible complex structure in the case when $M={\mathbb R}$ (I will leave it to you to extend it to any dimension).
The rank $2$ vector bundle $E  \to {\mathbb R}$ has to be trivial, $E={\mathbb R}\times {\mathbb R}^2$, with the standard fiberwise orientation. Now, take $U=(0,\infty)$ and a Hermitian metric $h$ on $E|_U$ given by the following family of Gram matrices.
$$
h_x= \left[\begin{array}{cc}
1&0\\
0& x^2\end{array}\right]. 
$$
The corresponding almost complex structure will not extend to the point $x=0\in M$.
One way to resolve the geometric issue is:
Proposition. Suppose that $E\to M$ is an oriented rank 2 vector bundle, $U\subset M$ is an open subset (connectedness of $U$ is irrelevant here) such that the restriction bundle $E|_U$ is equipped with a complex structure whose orientation is consistent with that of $E$. Then for every compact subset $K\subset U$, the complex structure on $E|_K$ extends to a complex structure on $E$, again, consistent with the orientation.
Proof. Let $h|_U$ be a Hermitian metric for the complex vector bundle $E|_U$. Let $V\subset U$ be a relatively compact open subset containing $K$. Take a locally finite open cover ${\mathcal W}$ of $M$ such that $V=W_0\in  {\mathcal W}$, the rest of the elements  $W_k\in {\mathcal W}, k\ge 1$, are disjoint from $K$ and $E$ is trivial over each $W_k, k\ge 1$. Let $h_k$ be a Hermitian metric on $E|_{W_k}, k\ge 1$;
set $h_0:=h|_V$. Now, take a partition of unity $\rho_k, k\ge 0$, for the cover ${\mathcal W}$ and use it to extend the Hermitian metric $h$ from $K$ to the rest of $M$:
$$
h= \sum_{k\ge 0} \rho_k h_k. 
$$
where, by default, $\rho_k h_k$ is extended by zero outside of $W_k$. qed
A: Here are some results concerning the possibility of giving the structure of a complex vector bundle to a differentiable real vector bundle $E$ of rank $2r$ on the differentiable manifold $M$  .
The principal tool here consists of the Stiefel-Whitney classes $w_i(E)\in H^i(M,\mathbb Z/2)$.
First necessary condition: odd Stiefel-Whitney classes
If $E$ has a complex structure, then all odd Stiefel-Whitney classes vanish: $$w_{2k+1}(E)=0$$ In particular $w_1(E)=0$, which is equivalent to $E$ being orientable.
So we retrieve the obvious necessary condition that $E$ be orientable.
Second necessary condition: even Stiefel-Whitney classes
Let $\mathcal E$ be a complex vector bundle with underlying real bundle $\mathcal E_\mathbb R=E$.
Then $\mathcal E$ has Chern classes $c_j(\mathcal E)\in H^{2j}(M,\mathbb Z)$ and we have $w_{2j}(E)=\operatorname {nat}(c_j(\mathcal E))$, where $\operatorname {nat}$ is the natural change of coefficients morphism $\operatorname {nat}:H^{2j}(M,\mathbb Z)\to H^{2j}(M,\mathbb Z/2)$.
This gives the necessary condition that the even Stiefel-Whitney classes of $E$ should be liftable from $\mathbb Z/2$ to $\mathbb Z$ coefficients.
An example of a non liftable Stiefel-Whitney class $w_2(E)$ of a $4$-dimensional vector bundle $E$ has been given by Bertram Arnold here, and that bundle can thus not be given a complex structure.
Warning
These necessary conditions are not sufficient for a real vector bundle to admit of a complex structure.
Many partial results are known but the general problem is (as far as I know) open.
Bibliography
The basics of characteristic classes are contained in Hatcher's freely available online document Vector Bundles and K-Theory.
