The buckling of nanotubes embedded in an elastic matrix is modeled within the framework of Timoshenko beams. Both a stress gradient and a strain gradient approach are considered. The energy variational approach is adopted to obtain the critical buckling loads. The dependences of the buckling load on the nonlocal parameter, the stiffness of the surrounding elastic matrix, and the transverse shear stiffness of the nanotubes are obtained. The results show a significant dependence of critical buckling load on the nonlocal parameter and the stiffness of the surround matrix. The Euler beam model, which neglects the shear stiffness of the nanotubes, over-predicts the critical buckling load. It is also found that the strain gradient model provides the lower bound and the stress gradient model provides the upper bound for the critical buckling load of nanotubes. In addition to mechanical buckling, thermally induced buckling of the nanotubes embedded in an elastic matrix is also studied. All results are expressed in closed-form and therefore are easy to use by materials scientists and engineers for the design of nanotubes and their composites.